I've received this quiz on an online form to apply for a recent Java event in my city:
//Instead of this comment what code should be written so you can get "Gotcha!" printed
if( a == a ){
System.out.println("Not yet...");
} else {
System.out.println("Gotcha!");
}
AFAIK: the == comparison in Java on objects checks if both objects are the same in memory, and overwriting the equals method doesn't overwrite the == operator like C++ and other languages that allow operator overloading
I tried to change a value with the following features in Java and none of them got me what I wanted:
- transient variable
- target annotation
- garbage collector
- mutable objects
What should I do to get the a object to be different from itself?