Virtual machines do not support these syntaxes,
Map<int,String> map = new HashMap<int,String>();map.put(1,"No.1");map.put(2,"No.2");System.out.println(map.get(1));System.out.println(map.get(2));
Map map = new HashMap();map.put(1,"No.1");map.put(2,"No.2");System.out.println((String)map.get(1));System.out.println((String)map.get(2));
import java.util.List;public class FanxingTest{public void method(List<String> list){System.out.println("List String");}public void method(List<Integer> list){System.out.println("List Int");}}
When I use
This is because of generics.
Modify the above Code as follows:
import java.util.List;public class FanxingTest{public int method(List<String> list){System.out.println("List String");return 1;}public boolean method(List<Integer> list){System.out.println("List Int");return true;}}
It is found that the compilation can be passed at this time (the language is not correlated with each other, and the two are of different types. They cannot be converted to each other, and there is no such situation as a non-zero integer in the language ). Adding two different types of return values makes the method reload successful. Why?
We know that the return value of a method is not involved in the selection of the method to be overloaded. It seems redundant to add the return value to the method to be overloaded. This is indeed redundant for the selection of overload methods, but the problem we need to solve now is that the above Code can be compiled, so that the two overload methods can reasonably coexist after adding different return values to the two overload methods, they can coexist in one
The syntax sugar, such as the automatic disassembly box and variable length parameters, are also restored to the native syntax structure during the compilation phase. Therefore, only the corresponding native type exists in the file, I will not describe them here.