Why does this compile:
class MaxMin<E extends Comparable<E>>
{
E max=null;
E min=null;
}
...but this doesn't?
class MaxMin<E implements Comparable<E>>
{
E max=null;
E min=null;
}
Generic type bounds only specify extends
and super
.
Quoting the Java Generics Tutorial(emphasis mine)
To declare a bounded type parameter, list the type parameter's name, followed by the extends keyword, followed by its upper bound, which in this example is Number. Note that, in this context, extends is used in a general sense to mean either "extends" (as in classes) or "implements" (as in interfaces)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With