fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. HashSet<Person> set=new HashSet<Person>();
  13. set.add(new Person(110,"1"));
  14. set.add(new Person(110,"1"));
  15. }
  16. }
  17. class Person{
  18. int id;
  19. String name;
  20. public Person(int id,String name){
  21. super();
  22. this.id=id;
  23. this.name=name;
  24. }
  25.  
  26. public int hashCode(){
  27. return this.id;
  28. }
  29.  
  30. public boolean equals(Object obj){
  31. Person p = (Person)obj;
  32. return this.id=p.id;
  33. }
  34.  
  35. public String toString(){
  36. return "编号:"+this.id+"name:"+this.name;
  37. }
  38.  
  39. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:32: error: incompatible types: int cannot be converted to boolean
		return this.id=p.id;
		              ^
1 error
stdout
Standard output is empty