• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

what is dereference?

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks marc. I did not know this before.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic