Java Reference
In-Depth Information
}
}
If you are desperate to avoid qualifying Arrays.toString invocations explicitly, you can write your
own private static forwarding method:
private static String toString(Object[] a) {
return Arrays.toString(a);
}
The static import facility was intended for situations in which static members of another class are
used repeatedly, and qualifying each use would seriously clutter a program. In such situations, the
static import facility can significantly enhance readability. It is far safer than implementing
interfaces to inherit their constants, which you should never do [EJ Item 17]. Overuse of the static
import facility can, however, harm readability by making the class of a static member unclear at the
point of use. Use the static import facility sparingly and only when there is a compelling need.
For API designers, be aware that the static import facility cannot be used effectively on a method if
its name is already in scope. This means that static import can seldom be used on static methods
that share names with methods in common interfaces, and it can never be used on static methods
that share names with methods found in Object . Once again, this puzzle demonstrates that name
reuse other than overriding is generally confusing. We have seen this with overloading, hiding, and
obscuring, and now we see it with shadowing.
< Day Day Up >
 
 
Search WWH ::




Custom Search