I knew that the generic type was added after Java5.0. At present, I have been reading 4.0 of entry books. For example, the second edition of "Java programming" published by Tsinghua University Press (edited by Tan Haoqiang and Ma Suxia) and Sun Xin's teaching video, which has been translated by Hou Jie, it seems that these books were made before 5.0, so I didn't know about generics in the learning process. Later, I only learned about generics intermittently, but I didn't take it seriously. today, programming has finally appeared.
When defining an Arraylist type, the following error occurs after compilation:
Note: checkUser. java uses unchecked or unsafe operations.
Note: Recompile with-Xlint: unchecked for details.
Baidu:
If it is displayed in Chinese, it is:
Note: a. java uses unchecked or insecure operations.
Note: for details, use-Xlint: unchecked to recompile.
In fact, it is very simple because the generic type of JAVA5.0 is used, while the generic type of 5.0 does not perform type check, for example, ArrayList a = new ArrayList ();
A. add ("hello"); in this case, a warning is displayed. There are several solutions:
1) add @ SuppressWarnings ("unchecked") before the method ")
2) declare generic types, such as ArrayList <Object> a = new ArrayList <Object> ();
3) use 1.4 compatible with JDK for compilation, javac-source 1.4 Test. java
4) You can also view the warning information, javac Xlint: unchecked Test. java. This will display detailed warning information