File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes can Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can "null" be considered as an object?" Watch "can "null" be considered as an object?" New topic
Author

can "null" be considered as an object?

kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87

above code compiles fine.does it mean that "null" is considered to be an object?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

"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.


[Jess in Action][AskingGoodQuestions]
kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87
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

Joined: Apr 10, 2010
Posts: 308
It's ok, exactly as if i write

Object o = null;

Reference o does not reference to any object.


Bye,
Nicola
kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87
thank you
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

I do not plan to hijack this thread,


but have a look at this:



the output amazed me:



My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
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
 
Consider Paul's rocket mass heater.
 
subject: can "null" be considered as an object?