> { E max=nul...">

Why does the common character "E implements I" lead to a compiler error?

Why is this compiling:

class MaxMin<E extends Comparable<E>> { E max=null; E min=null; } 

... but isn’t it?

 class MaxMin<E implements Comparable<E>> { E max=null; E min=null; } 
+7
source share
1 answer

Constraints of a general type indicate only extends and super .

Quote Java Generics Tutorial (highlighted by me)

To declare a parameter of a restricted type, specify the name of the type parameter, followed by the extends keyword, followed by its upper bound, which in this example is Number. Note that in this context, extensions are used in a general sense, meaning either "extends" (as in classes) or "implements" (as in interfaces)

+15
source

All Articles