Java编 了个小程序。。提示未经检查或不安全的操作

具体如下注意:SortedArray.java使用了未经检查或不安全的操作。注意:要了解详细信息,请使用-Xlint:unchecked重新编译。代码如下:publicc... 具体如下
注意:SortedArray.java使用了未经检查或不安全的操作。
注意:要了解详细信息,请使用-Xlint:unchecked重新编译。
代码如下:
public class SortedArray
{
public static int indexOf(int[] table,int value)
{
for (int i=0;i<table.length ;i++ )
{
if (table[i]==value)
return i;
}
return -1;
}
public static int indexOf(Comparable[] table,Comparable cobj)
{
if (table!=null&&cobj!=null)
{
for (int i=0;i<table.length&&cobj.compareTo(table[i])>=0 ;i++ )
{System.out.println(table[i]+"?");
if (cobj.compareTo(table[i])==0)
return i;}
}return -1;
}
public static void main(String[] args)
{
String[] keywords={"abstact","boolean","break","byte","case","catch",
"char","class","continue","defuault","do","double","else","extends","false",
"final","finally","float","for","if","implements","import","instanceof","int",
"interace","long","native","new","null","package","private","protected",
"public","return","short","static","super","switch","synchronized","this",
"throw","throws","transient","true","try","void","volatile","while"};
if (args.length>0)

for (int i=0;i<args.length ;i++ )
{
int find=SortedArray.indexOf(keywords,args[i]);
System.out.println(args[i]+((find!=-1)?"":"不")+"是关键字");
}
else
for (int i=0;i<args.length ;i++ )
{
String key="const";
int find=SortedArray.indexOf(keywords,key);
System.out.println(args[i]+((find!=-1)?"":"不")+"是关键字");
}
} }

我试过-Xlint了。。可还是不能用,也搜过一些方法。别人说是泛型。可不知道怎么解决。。求解。谢谢了。。分不多。。贵在求知。。呵呵。。
展开
 我来答
独行者311
推荐于2017-10-06 · 超过34用户采纳过TA的回答
知道答主
回答量:77
采纳率:0%
帮助的人:96.2万
展开全部
//是泛型的问题,加点东西就好了。
public class SortedArray {
public static int indexOf(int[] table, int value) {
for (int i = 0; i < table.length; i++) {
if (table[i] == value)
return i;
}
return -1;
}
//泛型是这样用的 <> Comparable中的类型必须是这个尖括号中的类型
public static int indexOf(Comparable<String>[] table,
Comparable<String> cobj) {
if (table != null && cobj != null) {
for (int i = 0; i < table.length
&& cobj.compareTo((String) table[i]) >= 0; i++) {
System.out.println(table[i] + "?");
if (cobj.compareTo((String) table[i]) == 0)
return i;
}
}
return -1;
}

public static void main(String[] args) {
String[] keywords = { "abstact", "boolean", "break", "byte", "case",
"catch", "char", "class", "continue", "defuault", "do",
"double", "else", "extends", "false", "final", "finally",
"float", "for", "if", "implements", "import", "instanceof",
"int", "interace", "long", "native", "new", "null", "package",
"private", "protected", "public", "return", "short", "static",
"super", "switch", "synchronized", "this", "throw", "throws",
"transient", "true", "try", "void", "volatile", "while" };
if (args.length > 0)

for (int i = 0; i < args.length; i++) {
int find = SortedArray.indexOf(keywords, args[i]);
System.out
.println(args[i] + ((find != -1) ? "" : "不") + "是关键字");
}
else
for (int i = 0; i < args.length; i++) {
String key = "const";
int find = SortedArray.indexOf(keywords, key);
System.out
.println(args[i] + ((find != -1) ? "" : "不") + "是关键字");
}
}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
youyougulin
2010-09-13 · 超过32用户采纳过TA的回答
知道答主
回答量:195
采纳率:0%
帮助的人:61.8万
展开全部
Comparable<T>[] 对 那个T需要换成你的类型
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式