fork download
  1. class Example2
  2. {
  3. private int content;
  4.  
  5. Example2(int content) {
  6. this.content = content;
  7. }
  8.  
  9. @Override
  10. public boolean equals(Object obj) {
  11. if (obj == null || !obj.getClass().equals(this.getClass())) {
  12. return false;
  13. }
  14. Example2 other = (Example2)obj;
  15. return this.content == other.content;
  16. }
  17.  
  18. @Override
  19. public int hashCode() {
  20. return this.content;
  21. }
  22.  
  23. public static void main (String[] args) throws java.lang.Exception
  24. {
  25. Example2 a = new Example2(42);
  26. Example2 b = new Example2(42);
  27. System.out.println(a == b ? "== Same" : "== Different");
  28. System.out.println(a.equals(b) ? "equals Same" : "equals Different");
  29. }
  30. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
== Different
equals Same