import java.util.*;public class SetExample
{
public static void main(String[] args)
{
Set set=new HashSet();
set.add("one");
set.add("second");
set.add("3rd");
set.add(new Integer(4));
set.add(new Float(3.0f));
set.add("second");
set.add(new Integer(4));
System.out.println(set);
}
}
为什么编译不了 我刚学,麻烦解释的详细点 谢谢
{
public static void main(String[] args)
{
Set set=new HashSet();
set.add("one");
set.add("second");
set.add("3rd");
set.add(new Integer(4));
set.add(new Float(3.0f));
set.add("second");
set.add(new Integer(4));
System.out.println(set);
}
}
为什么编译不了 我刚学,麻烦解释的详细点 谢谢
因为你使用Set set=new HashSet();创建set,未给它指定Set内保存的是什么类型
最好像这样:
Set<Object> set=new HashSet<Object>();
Set<String> set=new HashSet<String>();
import java.util.*;
public class SetExample
{
public static void main(String[] args)
{
Set<String> set=new HashSet<String>();//指定类型,String或者其它。
set.add("one");
set.add("second");
set.add("3rd");
//set.add(new Integer(4));
//set.add(new Float(3.0f));
set.add("second");
//set.add(new Integer(4));
System.out.println(set);
}
}