When you use the == operator on objects, you are comparing the REFERENCE - i.e. are the two variables pointing to the same spot in memory (more or less). Any time you use the "new" operator, you create a new object. When you do you get one string in the String Pool, and ANOTHER string is created on the stack. When you do it again, the same String pool string is used to create ANOTHER String on the stack.
So, with the code you show, you have one string of "123" in the String pool, and two additional objects in the stack.
You then compare if the two reference variable point to the same spot in memory, and since they are different objects on the stack, they do not. So, you get false.
If you had done
you should get true.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Jun 03, 2009
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com