Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is `AnyType` in java generics

Tags:

java

What is AnyType in java. When should i use it. For example TestRpn<AnyType extends Comparable<AnyType>> in this code snippet what is AnyType, and what kind of data it can have (i.e, like Integer,Boolean)

like image 745
chaitanya Avatar asked Jun 10 '26 20:06

chaitanya


1 Answers

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 Generic Types">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.

like image 163
Sean Patrick Floyd Avatar answered Jun 13 '26 08:06

Sean Patrick Floyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!