Java Reference
In-Depth Information
Continuing with the previous example we can extend
Base
as follows:
class Derived<T> extends Base<T> {
void m(Integer i){} // new overload
void m(Object t) {} // overrides m(T t)
void m(Number n) {} // overrides m(N n)
}
This introduces one new overloaded form of
m
and defines two overriding
implementations of
m
.
The simple rule to remember when thinking about overloading and over-
riding is to always consider the erasure of the method signatures and to
remember that you can't add genericity to an inherited method.