• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Autoboxing- dereference a primitive

 
Santiago Bravo
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following taken from whizlabs:





The answer is that Line 2 causes a compiler error as there is an attempt to reference the primitive type float.

I thought autoboxing will take care of line 2 it will compile and run ok.


Can anyone explain what is meant by dereferncing the primitive?

Thanks
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're asking the compiler to autobox and call the objects method... that is just something that isn't going to happen... just like it won't widen a primitive and then autobox (but it will box and then widen to object.

To do what you want it to do... you would have to have something like the following at Line 2:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic