This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I've never tried it, but your if condition looks like you are saying if null is an instance of String. Will that ever return true? And can you clarify your question a little? Are you confused as to why it is returning null when you aren't entering your if condition?
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Joined: Feb 12, 2010
What I meant was this :
The method is expecting a return type of Object , and am returning a null value and this compiles successfully. How is this poossible ?
You can assign a null value to any reference variable. But the null value is not an instanceof Object or any other class. When you assign a reference variable null, it means that the reference variable doesn't refer to any object.
Also this has been asked to you earlier by Christophe and I'm saying it again, try to ask the problem outside of the code. Instead of your question in the code itself, you can give the line that you are confused in a number and ask the question relative to that line number. Eg.
At line (2) I am able to return null here, the compiler doesnt complain. However when i do instanceOf Object at line (1) it doesnt enter the if loop. How is this possible ?