48

学习笔记——泛型-sun_tantan的博客-51CTO博客

 6 years ago
source link: http://blog.51cto.com/13580976/2067231
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
泛型的意义:泛型用来保证类型的统一,主要目的之一就是用来指定容器要持有什么类型的对象,而且由编译器来保证类型的正确性。1.类型安全,通过设置泛型,可以让编译器验证类型2.消除强制转换。如果不用泛型,将元素从容器中取出时,都是由object类型向目标类型强制转换。而由于泛型的擦除,所有的泛型类型变量都会被替换为原始类型,在获取的时候,集合会实现变量的强制转换,转换是隐式的。1.泛型类:publicc

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK