| Author |
what is dereference?
|
dolly shah
Ranch Hand
Joined: Jun 18, 2007
Posts: 383
|
|
This example is from Whizlabs. This code wont compile. The reason they have given is at line 1 we are attempting to dereference the primitive type float. I even heard "deference" word first time. Can anyone please help me?
|
SCJP-1.5<br />SCWCD-1.4
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
I know one such term 'dereferencing' with respect to 'C'/'C++' Pointers, which actually means 'taking out the value stored in a particular memory address being pointed to by this pointer value'. If, p is a pointer to an integer and it can be used as follows. Here, they would have meant to say the same 'unboxing' i think. As, boxing and unboxing are the means to convert your primitive to wrappers and vice versa. does that help dolly shah? [ October 08, 2007: Message edited by: Raghavan Muthu ]
|
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Variables do not hold objects. Instead, variables hold references to objects. So myVariable is just a reference -- not the object itself. But in order to call a method, we need the actual object. The dot operator "dereferences" the variable and "gets" the object. However, a primitive variable holds the actual value. It does not just reference it. Therefore, primitive variables cannot be dereferenced. So if you try to use the dot operator on a primitive variable, you will get the "cannot be dereferenced" error.
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
dolly shah
Ranch Hand
Joined: Jun 18, 2007
Posts: 383
|
|
|
Thanks marc. I did not know this before.
|
 |
 |
|
|
subject: what is dereference?
|
|
|