Java Reference
In-Depth Information
followed by “.” and an identifier. In the latter case, the specifier has the form
T.id
, where
compile-time error occurs. The specifier denotes that member type.
There are contexts in the Java programming language where a generic class or inter-
face name is used without providing type arguments. Such contexts do not involve the
sary for, or irrelevant to, the meaning of the generic class or interface.
For example, a single-type-import declaration
import java.util.List;
puts the simple type
name
List
in scope within a compilation unit so that parameterized types of the form
List<...>
may be used. As another example, invocation of a static method of a generic
class needs only to give the (possibly qualified) name of the generic class without any
type arguments, because such type arguments are irrelevant to a static method. (The
method itself may be generic, and take its own type arguments, but the type paramet-
ers of a static method are necessarily unrelated to the type parameters of its enclosing
generic class (§
6.5.5
).)
Because of the occasional need to use a generic class or interface name without type
arguments, type names are distinct from type declaration specifiers. A type name is
always qualified by means of another type name. In some cases, this is necessary to
access an inner class that is a member of a parameterized type.
Here is an example of where a type declaration specifier is distinct from a type name:
class GenericOuter<T extends Number> {
public class Inner<S extends Comparable<S>> {
T getT() { return null;}
S getS() { return null;}
}
}
class Test {
public static void main(String[] args) {
GenericOuter<Integer>.Inner<Double> x1 = null;
Integer i = x1.getT();
Double d = x1.getS();
}
}
If we accessed
Inner
by qualifying it with a type name, as in:
GenericOuter.Inner x2 = null;