Basic HTML version of Foils prepared 13 July 98

Foil 23 Comparing Colors

From Java Academy II:Intermediate Java NPAC/ECS Java Academy -- February to April 98. by Tom Scavo


1 Suppose you are given an unknown color c
2 To check if c is red, use: if ( c.equals( Color.red ) ) ...
3 Do not use if ( c == Color.red ) ... since this comparison will always be false!
4 The reason is subtle: c and Color.red are distinct objects (although their values are equal)

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998