为什么使用泛型的代码编译? [英] Why does this code with generics compile?

查看:131
本文介绍了为什么使用泛型的代码编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个愚蠢的问题,但我现在正在绊倒它。为什么这样编译?

  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
>这


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"?

解决方案

See this Also this

这篇关于为什么使用泛型的代码编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆