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. List<Foo> foos = Arrays.asList(new Foo(7));
  13. System.out.printf("%b%n", foos.contains(new Bar(7)));
  14. }
  15.  
  16. private static class Foo {
  17. private final int x;
  18.  
  19. public Foo(int x) {
  20. this.x = x;
  21. }
  22.  
  23. @Override
  24. public boolean equals(Object other) {
  25. if (!(other instanceof Foo)) {
  26. return false;
  27. }
  28. return this.x == ((Foo)other).x;
  29. }
  30. }
  31.  
  32. private static class Bar extends Foo {
  33. public Bar(int x) {
  34. super(x);
  35. }
  36. }
  37. }
Success #stdin #stdout 0.08s 381184KB
stdin
Standard input is empty
stdout
true