It's just Override. The code of ↓ that I wrote earlier changes the processing to "dynamic" with Proxy, but this one is just "static".
[I want to output true in Java with a == 1 && a == 2 && a == 3 (gray magic that is not so much black magic) --Qiita](https://qiita.com/momosetkn / items / 48039a6c0ee84f3979fa)
public class JudgeImpl2 {
public static void main(String... args) throws Exception {
{
System.out.println("First of all, if you execute it normally ...");
JudgeImpl2 judge = new JudgeImpl2();
test(judge);
}
{
System.out.println("If you overwrite ...");
JudgeImpl2 judge = new JudgeImpl2() {
@Override
public boolean judge(int a ) {
return true;
}
};
test(judge);
}
}
private static void test(JudgeImpl2 judge){
System.out.println( judge.judge(1) );
System.out.println( judge.judge(2) );
System.out.println( judge.judge(3) );
}
public boolean judge(int a) {
if (a == 1 && a == 2 && a == 3) {
return true;
} else {
return false;
}
}
}
First of all, if you execute it normally ...
false
false
false
If you overwrite ...
true
true
true
Recommended Posts