December 1999
Intermediate to advanced
816 pages
20h 27m
English
Choose names carefully for clarity. Apart from names that don't communicate anything meaningful like doIt(), avoid the common technique of naming parameters the same as data members. Listing 5.1 shows poor parameter name choices.
public class LibraryCard
{
String name;
int value;
public boolean verify(String name, int value)
{
name = "Ted"; // Don't do this
// if you want to assign "Ted" to the
// data member name.
}
}
|
When Java looks at a variable name in a method, it has to decide in each case whether you are referring to a data member, local variable, or parameter. By default, Java first assumes you meant a parameter. In the preceding code, that is not what was intended, because ...
Read now
Unlock full access