I just rounded up some cattle at The JavaRanch Rules Round-up Game. I noticed the following question:
(#16) Integer a=new Integer(5); Integer b = new Integer(5); What is the result of running if (a==b)
The real answr is true, not false
The Integer (maybe most wrapper classes) is an exception to the rule stated in the explanation. It does return true for low numbers as the following code-snippet shows:
Kind Regards, Cecilia
isn't the same as one in the game:
Integer a=new Integer(5);
Integer b = new Integer(5);
See this discussion, about what I mean.
Thank you for explaining. I will be careful to copy the exact code next time I test a question.
Cecilia Burman wrote:I also found this question:
(#98) All exceptions ingerit from:
With the explanation:
"The Exception hierarchy begins at java.lang.Throwable"
IMHO all exceptions inherit from both Throwable and Exception. Isn't that so?
Not really. When people talk about "exceptions" or "exception handling", note the lower case, they often mean any Throwable. Like wise they often say "error" or "error handling" when they really mean any Throwable. The problem is that "throwable handling" isn't a term you could use outside the Java community, and it would be tedious to say "error and exception handling" instead. So informally, people use these terms more loosely. But if you capitalize the terms, it's clear you're talking about Error or Exception as specific Java classes, and the ambiguity goes away.