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);
                 
         }
}
为什么编译不了 我刚学,麻烦解释的详细点 谢谢

解决方案 »

  1.   

    编译肯定能通过,只不过会提示你的代码不安全
    因为你使用Set set=new HashSet();创建set,未给它指定Set内保存的是什么类型
    最好像这样:
    Set<Object> set=new HashSet<Object>();
    Set<String> set=new HashSet<String>();

      

  2.   

    编译可以,只是这里是泛型,你没指定,java就提醒你这样不稳定嘛、
      

  3.   


    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);
      }
    }