简体   繁体   中英

What is `AnyType` in java generics

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 (ie, like Integer,Boolean)

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.

AnyType is actually used in java7+. It can be said that its usage is same as that of E or T or something. As the name suggests it can any type of generic data. for example, when I implemented my generic linked list in Java, I used

private Node<AnyType> head;

where the word AnyType stands for the generic type Node.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM