This content has been marked as final. Show 2 replies
Vrishali.Bobade wrote:Terminology: either use 'object', 'object instance' or 'reference' rather than 'object name'
Is there a difference between the way the compiler handles the null check of any java object:
if(null != <object name>)
Question 1: Is there a difference as regards how the compiler processes the above two statements? Is one of the method more efficiently handled than the other?No.
If no thenSome people do that because they used C/C++ which allows the following
Question 2: Why is it a coding practice to usually follow Method 1?
if (pointer = null)
Notice in the above that it is "=" and not "==". What happens in that case that assignment actually occurs. This represented an error in their code. Thus the practice you stated which disallows that possibility.
k got the answer and thanks for correcting me :) .