1. A local type (such as int float) cannot be used to replace the generic type.
2. runtime type check. Different types of generic classes are equivalent (pair and pair belong to the same type of pair). Pay special attention to this, that is, if a instanceof pair = true, it does not mean. the return value of getfirst () is a string type.
3. The generic class cannot inherit the exception class, that is, the generic class cannot be thrown as an exception.
4. Generic arrays cannot be defined.
5. The object cannot be constructed using generics, that is, first = new T (); it is incorrect.
6. You cannot use generics in the static method, or modify generic variables with the static keyword.
7. Do not define equals (t x) methods in generic classes, because the equals method also exists in the object class. When the generic class is erased, the two methods conflict.
8. There is no relationship between multiple classes derived from the same generic class. values cannot be assigned to each other, that is:
Pair P1; pair P2; P1 = P2; this assignment is incorrect.
9. If a generic class has a non-generic class with the same name, do not mix them. Always use a generic class.
Pair <Manager> managerbuddies = new pair <Manager> (CEO, CFO );
Pair rawbuddies = managerbuddies;
Here, the compiler will not report errors, but there is a serious runtime error risk.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service