What is `AnyType` in java generics

There is no predefined type named AnyType. I am guessing you have come across a poorly named type parameter variable. The naming convention for type variables is suggested to be single uppercase letters, to avoid this type of confusion.

In your case, TestRpn<AnyType extends Comparable<AnyType>> should be rephrased as TestRpn<E extends Comparable<E>>, which in turn means that you can substitute any type for E that implements Comparable for it’s own type. Example: java.lang.String implements Comparable<String>, so TestRpn<String> is a valid parametrization of the above base type.

Leave a Comment