简体   繁体   English

Java源代码中的泛型编程

[英]Generic programming in Java source code

Arrays and Collections are two basic api classes used by all java programmers. 数组和集合是所有Java程序员都使用的两个基本api类。 Both the classes were added in Java 1.2 这两个类都是在Java 1.2中添加的

Looking at Arrays class, there are 27 overloaded binarysearch methods and it has no usage of Generics where as collections is updated to use generics. 在Arrays类上,有27种重载的binarysearch方法 ,它没有使用Generics,因为集合被更新为使用Generic。 Where as Collections class has 2 overloaded binary search methods. 其中,Collections类具有2个重载的二进制搜索方法。

Any reason why it is done this way or am i missing any thing? 以这种方式完成的任何原因还是我错过了任何东西?

Because Java generics can only be parameterised on reference types. 因为Java泛型只能在引用类型上参数化。 int , long , etc. are primitive types. intlong等是原始类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM