Java Reference
In-Depth Information
freely generify methods independently of clients that define subclasses or subinter-
faces of the library.
Consider the example:
class CollectionConverter {
List toList(Collection c) {...}
}
class Overrider extends CollectionConverter {
List toList(Collection c) {...}
}
Now, assume this code was written before the introduction of generics, and now the
author of class
CollectionConverter
decides to generify the code, thus:
class CollectionConverter {
<T> List<T> toList(Collection<T> c) {...}
}
Without special dispensation,
Overrider.toList
would no longer override
CollectionConvert-
er.toList
. Instead, the code would be illegal. This would significantly inhibit the use of
generics, since library writers would hesitate to migrate existing code.
8.4.3. Method Modifiers
MethodModifiers:
MethodModifier
MethodModifiers MethodModifier
MethodModifier: one of
Annotation
public protected private abstract
static final synchronized native strictfp
must have an element whose value is
java.lang.annotation.ElementType.METHOD
, or a compile-
time error occurs.
It is a compile-time error if the same modifier appears more than once in a method declar-
ation, or if a method declaration has more than one of the access modifiers
public
,
protected
,
It is a compile-time error if a method declaration that contains the keyword
abstract
also
contains any one of the keywords
private
,
static
,
final
,
native
,
strictfp
, or
synchronized
.