Forums Register Login

can "null" be considered as an object?

+Pie Number of slices to send: Send

above code compiles fine.does it mean that "null" is considered to be an object?
+Pie Number of slices to send: Send
"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.
+Pie Number of slices to send: Send
 

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?
+Pie Number of slices to send: Send
It's ok, exactly as if i write

Object o = null;

Reference o does not reference to any object.
+Pie Number of slices to send: Send
thank you
+Pie Number of slices to send: Send
I do not plan to hijack this thread,


but have a look at this:



the output amazed me:


+Pie Number of slices to send: Send
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
Let's go to the waterfront with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1055 times.
Similar Threads
invocations prob::
overloading doubt
Method invocation doubt?
Method invocations
overriding & overloading
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:45:08.