Understanding bounded generics in java. What is the point?
问题 I am trying to understand bounded types and not quite grasping the point of them. There is an example of bounded generics on which provides this use case: public class NaturalNumber<T extends Integer> { private T n; public NaturalNumber(T n) { this.n = n; } public boolean isEven() { return n.intValue() % 2 == 0; } // ... } If you are going to restrict the classes that can be the parameterized type, why not just forget the parameterization all together and have: public class NaturalNumber {