Java Arrays.binarySearch(Object[], int, int, Object) 签名无法识别
我正在尝试使用 Java API 规范 但我的 IDE Eclipse (Helios) 不是识别签名。
我的类,归结为它的 2 个数据成员和我尝试调用 Arrays.binarySearch 的方法:
import java.util.Arrays; // Access Arrays class
public class SortedStringArrayList {
// member data
private String[] items;
private int size;
// methods
public int testBinSearch(String item) {
int index = Arrays.binarySearch(items, 0, size, item);
}
}
当我在该方法中编码时,Eclipse 假设我想要一个不同的签名并告诉我:
方法binarySearch(int[], int)中 数组类型不适用于 参数 (String[], int, int, 字符串)
它建议可用的 binarySearch 签名是:
我对 Java/Eclipse 非常陌生。有人知道问题是什么吗?
I'm trying to use the binarySearch method documented at the Java API Specification but my IDE, Eclipse (Helios), is not recognizing the signature.
My class, boiled down to its 2 data members and the method in which I'm trying to call the Arrays.binarySearch:
import java.util.Arrays; // Access Arrays class
public class SortedStringArrayList {
// member data
private String[] items;
private int size;
// methods
public int testBinSearch(String item) {
int index = Arrays.binarySearch(items, 0, size, item);
}
}
When I code in the method, Eclipse assumes I want a different signature and tells me:
The method binarySearch(int[], int) in
the type Arrays is not applicable for
the arguments (String[], int, int,
String)
The signatures for binarySearch it suggested as available were:
I'm very new to Java/Eclipse. Anyone know what the problem is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要告诉 Eclipse 使用 Java 1.6(在项目设置下)。我猜你用的是1.5。 1.5及更早版本只有基本版本的
binarySearch
,没有fromIndex
或toIndex
。如果您希望拥有较旧 JRE 的用户能够运行您的程序,您可以从 1.6 源 并将其粘贴到您自己的代码中。
You need to tell Eclipse to use Java 1.6 (under project settings). I'm guessing you're on 1.5. 1.5 and older versions only have the basic version of
binarySearch
, with nofromIndex
ortoIndex
.If you want users with older JREs to be able to run your program, you could copy the
binarySearch
implementations from the 1.6 source and paste it into your own code.