Java Reference
In-Depth Information
If you want to guarantee the prize in the Jeopardy class even while preserving the ability to
subclass it, use a final method instead of a final field:
class Jeopardy {
private static final String PRIZE = "$64,000";
public static final String prize() {
return PRIZE;
}
}
For language designers, the lesson is to avoid reusing the same keyword for unrelated concepts. A
keyword should be reused only for closely related concepts, where it helps programmers build an
intuition about the relationship among the language features in question. In the case of the Java's
final keyword, reuse leads to confusion. It should be noted that as a language ages, there is a
natural tendency to reuse keywords for unrelated concepts. This avoids the need to introduce new
keywords, which is enormously destabilizing. When language designers do this, they are generally
choosing the lesser of two evils.
In summary, avoid reusing names for unrelated variables or unrelated concepts. Using distinct
names for unrelated concepts helps readers and programmers to keep the concepts separate.
< Day Day Up >
 
 
Search WWH ::




Custom Search