Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Royal road edition that is neither magic nor anything)

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;
        }
    }
}

Execution result

First of all, if you execute it normally ...
false
false
false
If you overwrite ...
true
true
true

Recommended Posts

Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Royal road edition that is neither magic nor anything)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
I want to ForEach an array with a Lambda expression in Java
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
Output true with if (a == 1 && a == 2 && a == 3) in Java (Invisible Identifier)
Even if I want to convert the contents of a data object to JSON in Java, there is a circular reference ...
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I want to create a Parquet file even in Ruby
[Java] I want to test standard input & standard output with JUnit
I want to write a loop that references an index with Java 8's Stream API
A story that I struggled to challenge a competition professional with Java
[Java] I want to perform distinct with the key in the object
I want to select multiple items with a custom layout in Dialog
I want to create a dark web SNS with Jakarta EE 8 with Java 11
I want to display a PDF in Chinese (Korean) with thin reports
I tried to make a program that searches for the target class from the process that is overloaded with Java
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
I want to send an email in Java.
I did Java to make (a == 1 && a == 2 && a == 3) always true
I want to use java8 forEach with index
rsync4j --I want to touch rsync in Java.
I tried to output multiplication table in Java
I want to be eventually even in kotlin
I tried to break a block with java (1)
I want to use PowerMock in a class that combines parameterized tests and ordinary tests
I want to return an object in CSV format with multi-line header & filter in Java
I made a function to register images with API in Spring Framework. Part 1 (API edition)
I want to do something like "cls" in Java
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I want to use a little icon in Rails
I tried to create a Clova skill in Java
I want to monitor a specific file with WatchService
I tried to make a login function in Java
I want to define a function in Rails Console
I want to transition screens with kotlin and java!
I want to click a GoogleMap pin in RSpec
I want to get along with Map [Java beginner]
How to batch initialize arrays in Java that I didn't know when I was a beginner
[CQ Engine] I want to handle collections like Stream or .Net LINQ even in Java 7.
I want to return a type different from the input element with Java8 StreamAPI reduce ()
I made a function to register images with API in Spring Framework. Part 2 (Client Edition)
I made a program in Java that solves the traveling salesman problem with a genetic algorithm
I tried to create a java8 development environment with Chocolatey
[Java] I want to convert a byte array to a hexadecimal number
I want to find a relative path in a situation using Path
[Beginner] I made a program to sell cakes in Java
I just wanted to make a Reactive Property in Java
I tried to convert a string to a LocalDate type in Java
I tried to make a client of RESAS-API in Java
I want to implement various functions with kotlin and java!
I want to simplify the conditional if-else statement in Java
[Java] I want to check that the elements in the list are null or empty [Collection Utils]
[Wire Mock] I want to set up a stub / mock server in Java and perform E2E tests.
How to deal with the type that I thought about writing a Java program for 2 years