未检查或不安全的操作错误 [英] unchecked or unsafe operation error
本文介绍了未检查或不安全的操作错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经制作了这个程序来寻找最长的渐进序列。虽然它运行但我收到以下编译时错误:
Sequence.java使用未经检查或不安全的操作。
使用-Xlint重新编译:取消选中以获取详细信息。
I have made this program for finding the Longest progressive sequence. Though it runs but I am getting the following compile time error: Sequence.java uses unchecked or unsafe operations. Recompile with -Xlint:unchecked for details.
import java.util.Scanner;
import java.util.TreeSet;
public class Sequence
{
public static void main(String [] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the length of the sequence");
int t=s.nextInt();
System.out.println("Enter the elements of the sequence");
int seq[]=new int[t];
TreeSet ans=new TreeSet();
int i,j;
for(i=0;i<seq.length;i++)
{
seq[i]=s.nextInt();
}
for(i=seq.length-1;i>=0;i--)
{
int k=seq[i];
boolean f=true;
for(j=i-1;j>=0;j--)
{
if(k<seq[j])
{
f=false;
}
}
if(f==true)
ans.add(k);
}
Object[] obj=ans.toArray();
for(i=0;i<obj.length;i++)
{
System.out.print(obj[i]+" ");
}
}
}
怎么做我纠正了我的错误?
How do I rectify my mistake?
推荐答案
TreeSet是一个通用类。你需要给它一个类型。看起来你要在其中添加 ints
,所以正确的声明将是
TreeSet is a generic Class. You need to give it a type. It looks like you're adding ints
into it, so the correct declaration would be
TreeSet<Integer> ans = new TreeSet<>();
或者,在Java7之前的版本中,
or, in pre Java7 versions,
TreeSet<Integer> ans = new TreeSet<Integer>();
这篇关于未检查或不安全的操作错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文