문제

Whu Do it is a non-valid construction

class A <T extends  String & Comparable<T>>{}

out:

java: java.lang.Comparable cannot be inherited with different arguments: <T> and <java.lang.String>

but it is valid

class A <T extends  Number & Comparable<T>>{}

I noiced that it is related with String is final but Number - not.

But T String is valid at first case I think. Why not?

도움이 되었습니까?

해결책

The difference is, String class already implements Comparable<String>, while Number class doesn't. So, with that bound, T would be implementing both Comparable<String> and Comparable<T>, which is not allowed.

A class cannot extend from or implement different parameterized instantiation of a generic type.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top