import java.util.*;public class BasicContainer{
public static void main(String[] args){
Collection c = new HashSet();
c.add("hello");
c.add(new Name("f1","11"));
c.add(new Integer(100));
c.remove("hello");
c.remove(new Interger(100));
System.out.println(c.remove(new Name("f1","11")));
System.out.println(c);
}
} class Name{
private String firsName,lastName;
public Name(String firstName,String lastName){
this.firstName = firstName; this.lastName = lastName;
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String toString(){
return firstName + " " + lastName;
}
}问各大侠哪错了,咋改;

解决方案 »

  1.   

    不知道啊,提示我Collection c = new hashSet();不兼容啊
      

  2.   

    我用eclipse给你编译运行了一下。
    你这个程序一共2处错误import java.util.*;public class BasicContainer{
    public static void main(String[] args){
    Collection c = new HashSet();
    c.add("hello");
    c.add(new Name("f1","11"));
    c.add(new Integer(100));
    c.remove("hello");
    c.remove(new Interger(100));//多打了一个r,自己看看
    System.out.println(c.remove(new Name("f1","11")));
    System.out.println(c);
    }
    }class Name{
    private String firsName,lastName;//定义的时候少打了一个t
    public Name(String firstName,String lastName){
    this.firstName = firstName; this.lastName = lastName;
    }
    public String getFirstName(){
    return firstName;
    }
    public String getLastName(){
    return lastName;
    }
    public String toString(){
    return firstName + " " + lastName;
    }
    //最后的结果是
    false
    [f1 11]
    这结果不知道是不是你想要的。
    如果不是特别新手的话,而且经常打错代码的话,就弄一个编译环境用吧。省时间,不容易出错
      

  3.   

    import java.util.Collection; // 1、你没有 import
    import java.util.HashSet;public class BasicContainer {
    public static void main(String[] args) {
    Collection c = new HashSet();
    c.add("hello");
    c.add(new Name("f1", "11"));
    c.add(new Integer(100));
    c.remove("hello");
    c.remove(new Integer(100));// 2、你的Integer都写错了
    System.out.println(c.remove(new Name("f1", "11")));
    System.out.println(c);
    }
    }class Name {
    private String firstName, lastName;  //3、 你的firstName 都写错了,
    //接下来看看还有没有问题,再说··· public Name(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    } public String getFirstName() {
    return firstName;
    } public String getLastName() {
    return lastName;
    } public String toString() {
    return firstName + " " + lastName;
    }
    }
      

  4.   


    LZ用的是eclipse么? 快捷键: “Shift + /”吧,不用什么都手工敲代码,效率低哈···
      

  5.   

    http://bbs.csdn.net/topics/390275427?page=1#post-392867820
      

  6.   

    import java.util.*;不都包括了那俩包吗
      

  7.   


    用的JCreator,改正后是这样的
      

  8.   

    路过,你定义的    Collection c = new HashSet();    是向父类传子类?
      

  9.   

    http://bbs.csdn.net/topics/240028892跟这个问题是一样的,import java.util.*不起作用,改成util.Collection,...util.HashSet,就能编译通过
      

  10.   


    import java.util.*;public class BasicContainer{
    public static void main(String[] args){
    Collection<Object> c = new HashSet<Object>();
    c.add("hello");
    c.add(new Name("f1","11"));
    c.add(new Integer(100));
    c.remove("hello");
    c.remove(new Integer(100));//Ingeger

    System.out.println(c.remove(new Name("f1","11")));
    System.out.println(c);
    }
    }
     
    class Name{
    private String firstName,lastName;//firstName
    public Name(String firstName,String lastName){
    this.firstName = firstName; 
    this.lastName = lastName;
    }
    public String getFirstName(){
    return firstName;
    }
    public String getLastName(){
    return lastName;
    }
    public String toString(){
    return firstName + " " + lastName;
    }
    }