Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can "null" be considered as an object?

 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

above code compiles fine.does it mean that "null" is considered to be an object?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"null" is a reference to "no object" -- it is not an object, but just a "pointer" that points to nothing. It is automatically assumes any reference type, so that null means "no String", or "no Object", or "no JFrame", or whatever.
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:"null" is a reference to "no object" -- it is not an object, but just a "pointer" that points to nothing. It is automatically assumes any reference type, so that null means "no String", or "no Object", or "no JFrame", or whatever.

thanks
but in the above code hasnt "null" been taken as a reference to an object that the code compiles?
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's ok, exactly as if i write

Object o = null;

Reference o does not reference to any object.
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
salvin francis
Bartender
Posts: 1280
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not plan to hijack this thread,


but have a look at this:



the output amazed me:


 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well that's a matter of method invocation.

I searched trough the language specification and i found this:

When a method is invoked,the number of actual arguments (and any explicit type arguments) and the compile-time types of the arguments are used, at compile time, to determine the signature of the method that will be invoked...


15.12.2 Compile-Time Step 2: Determine Method Signature
The second step searches the type determined in the previous step for member methods. This step uses the name of the method and the types of the argument expressions to locate methods that are both accessible and applicable, that is, declarations that can be correctly invoked on the given arguments. There may be more than one such method, in which case the most specific one is chosen. The descriptor (signature plus return type) of the most specific method is one used at run time to perform the method dispatch.


Overloading
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic