Generics:
package Java basic enhancement; import java.util.ArrayList;import java.util.List;import org.junit.Test;public class Test2 {@Testpublic void fun1(){Object[] objects = new Object[10];List list = new ArrayList();String[] strings = new String[10];List<String> list2 = new ArrayList<String>();Object[] objects2 = new String[10];//The following sentence does not report an error in compilation, but the running package storage error is abnormal. objects2[0]=new Integer(100);//java.lang.ArrayStoreException: java.lang.Integer//The following sentence reports an error in compilation//List<Object> objects3 = new ArrayList<String>();/* * Generic reference and creation ends, the given generic variables must be consistent* The virtual machine does not check whether the generic exists at all*/}public void fun2(){List<Integer> list = new ArrayList<Integer>(); this.print1(list);//1.print1 method can only store Integer, and cannot make Object//======================================================================================================================================================================================================================================================================================================================================================================================================================================================================================== void print1(List<Integer> objects){}public void print2(List<String> strings){}//But later a clever programmer used wildcards to solve the problem that this generic cannot be overloaded public void print(List<? extends Object> list){}//But the following two ordinary methods can overload public void a(String s){}public void a(int i){}}Generic methods cannot be overloaded because the generics are erased with the same method, that is, if the formal parameters in a method are generic, this method cannot be overloaded, that is, even if the method name is the same and the parameters are different, ordinary methods can be overloaded (different parameters of the same name)
The HTML was originally planned to transition to XML, and there was an XHTML in the middle, but it had not been successfully transferred after 10 years of migration. As a result, the HTML was upgraded, and it was HTML5. It was finally declared that the migration failed. It would be better to use HTML.
In fact, after JDK1.5, generics can be added. Although they can be checked by the compiler, many criticisms have been introduced. In fact, after compilation, generics have been removed, which means that Java virtual machines do not recognize generics.
The above is the brief discussion that the editor brings to you about Java generic wildcards solving many criticisms of generics (such as not being overloaded). I hope it will be helpful to everyone and support Wulin.com more~