<里面的数据类型有什么作用?>在爪哇? [英] What is the role of the data types inside of < > in Java?

查看:30
本文介绍了<里面的数据类型有什么作用?>在爪哇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
Java 泛型

更具体地说,下面这行代码中的作用是什么?

To be more specific, whats the role of the <String> in the following line of code?

private List<String> item = new ArrayList<String>();

推荐答案

主要是为了允许编译器在您没有将正确类型的数据插入列表中或者您期望从列表中获得错误类型的数据时引发错误提取时的列表

Mainly to allow the compiler to raise an error if you don't insert the right kind of data into the list or if you expect data of the wrong type from the list at the moment of extraction

但请参阅泛型教程以获取解释:http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html

But see the generics tutorial for an explanation: http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html

这篇关于&lt;里面的数据类型有什么作用?&gt;在爪哇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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