为什么使用泛型的代码编译? [英] Why does this code with generics compile?
本文介绍了为什么使用泛型的代码编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import java.util。*;
public class Test {
public static void main(String [] argv)throws Exception {
Map< String,String> map = new HashMap< String,String>();
map.get(new ArrayList< String>());
用一些东西调用get不是非法的这与字符串不兼容? 解决方案
This seems like a stupid question, but I'm tripping over it at the moment. Why does this compile?
import java.util.*;
public class Test {
public static void main (String[] argv) throws Exception {
Map<String,String> map = new HashMap<String,String>();
map.get(new ArrayList<String>());
}
}
Shouldn't it be illegal to call get with something that's not compatible with "String"?
解决方案
这篇关于为什么使用泛型的代码编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文