Java Reference
In-Depth Information
MyString s = new MyString ("Hello world");
System.out.println(s);
}
}
class MyString {
private final String s;
public MyString (String s) { this.s = s; }
public String toString() { return s; }
}
Broadly speaking, the lesson of this puzzle is to avoid the reuse of class names, especially Java
platform class names. Never reuse class names from the package java.lang . The same lesson
applies to library designers. The Java platform designers slipped up a few times. Notable examples
include java.sql.Date , which conflicts with java.util.Date , and org.omg.CORBA.Object . As in
many other puzzles in this chapter, the lesson is a specific case of the principle that you should
avoid name reuse, with the exception of overriding. For platform implementers, the lesson is that
diagnostics should make clear the reason for a failure. The VM could easily have distinguished the
case where there is no main method with the correct signature from the case where there is no main
method at all.
< Day Day Up >
 
 
Search WWH ::




Custom Search