为什么Java中的泛型使用类而不是基本类型?
例如,这工作正常:
List<Integer> foo = new ArrayList<Integer>();
Run Code Online (Sandbox Code Playgroud)
但这是不允许的:
List<int> bar = new ArrayList<int>();
Run Code Online (Sandbox Code Playgroud) 据我了解,C#/ .Net泛型支持某种程度的具体化.所以,如果我有以下代码:
List<int> list = new List<int>();
list.Add(1);
Run Code Online (Sandbox Code Playgroud)
值1是自动装箱还是'list'对象会有效地处理原始int?