Super and extends in java generic

Question about java generic:
Why is “extends T” allowed but not “implements T”?

Answer:

There is no semantic difference in the generic constraint language between whether a class ‘implements’ or ‘extends’. The constraint possibilities are ‘extends’ and ‘super’ – that is, is this class to operate with assignable to that other one (extends), or is this class assignable from that one (super).

Reference: http://stackoverflow.com/questions/976441/java-generics-why-is-extends-t-allowed-but-not-implements-t

Additional Example of super and extends in java generic:
http://stackoverflow.com/questions/6826916/useful-example-with-super-and-obscurity-with-extends-in-generics/6828257#6828257

Advertisements

About yingding wang
i am looking forward to innovation in IT and Robotics

Comments are closed.

%d bloggers like this: