How can a Java variable be different from itself?

Viewed 4044

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:

  1. transient variable
  2. target annotation
  3. garbage collector
  4. mutable objects

What should I do to get the a object to be different from itself?

0 Answers
Related