== じゃなくて、equals ならできる……

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class Main {

    public static void main(String[] args) {
        
        MyInt a = new MyInt(1);

        if (a.equals(1) && a.equals(2) && a.equals(3)) {
            System.out.println("true");
        } else {
            System.out.println("false");
        }    
    }
}

class MyInt {
    int i;

    public MyInt(int i) {
        this.i = i;
    }

    @Override
    public boolean equals(Object i) {
        return (int)i == this.i++;
    }
}

1
2
3
$ javac Main.java
$ java Main
true