Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
java_language_specification_7.pdf
Скачиваний:
30
Добавлен:
21.03.2016
Размер:
3.11 Mб
Скачать

CLASSES

Inheritance, Overriding, and Hiding

8.4.8

class

C<T> {

 

T

id (T x) {...}

 

}

 

 

class

D extends C<String> {

 

Object id(Object x) {...}

}

This is illegal since D.id(Object) is a member of D, C<String>.id(String) is declared in a supertype of D, and:

The two methods have the same name, id

C<String>.id(String) is accessible to D

The signature of D.id(Object) is not a subsignature of that of

C<String>.id(String)

The two methods have the same erasure

Two different methods of a class may not override methods with the same erasure:

class C<T> {

T id(T x) {...}

}

interface I<T> { T id(T x);

}

class D extends C<String> implements I<Integer> { public String id(String x) {...}

public Integer id(Integer x) {...}

}

This is also illegal, since D.id(String) is a member of D, D.id(Integer) is declared in D, and:

The two methods have the same name, id

D.id(Integer) is accessible to D

The two methods have different signatures (and neither is a subsignature of the other)

D.id(String) overrides C<String>.id(String) and D.id(Integer) overrides

I.id(Integer) yet the two overridden methods have the same erasure

8.4.8.4 Inheriting Methods with Override-Equivalent Signatures

It is possible for a class to inherit multiple methods with override-equivalent signatures (§8.4.2).

It is a compile-time error if a class C inherits a concrete method whose signature is a subsignature of another concrete method inherited by C. This can happen if

237

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]