Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper class question

 
Luca Cazzaniga
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
what happens when the code creates a new Wrapper obj assigning a primitive value as follows

Short s=2;

It compiles.. but I don't get why.. shouldn't the compiler autobox the primitive value with an implicite call to Integer.valueOf(2)?
I presumed so becouse there is only a method Short.valueOf(short) and calling it with a integer argument yields a compilation issue:

error: no suitable method found for valueOf(int)
Short s=Short.valueOf(2);

so I thought the code yelds to a wrong assignment as
Short s=Integer.valueOf(2);

I tried to use javap to decompile but I can't decode the output..

Could you confirm the wrapper class is matter of the oca test?
I found some questions about that in the Deshmukh's oca 1z0-803 book so I would like to dig into the subject..

Any helps will be really appreciate.


Best regards
 
Roel De Nijs
Sheriff
Posts: 10041
127
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the Java compiler is a real brainiac

Let's take this little program:


When I decompile the compiled class file, I get this java code:


So the java compiler does a whole lot behind the scenes!
 
Luca Cazzaniga
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Roel, thanks for your time and enlightments,

can I ask you what do you use to decompile? Does the decompiler's output provide a straight way to show all the work behind the scene and understand the building steps?


Best regards

Luca
 
Roel De Nijs
Sheriff
Posts: 10041
127
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Luca,

I have always used the JAva Decompiler (JAD). It isn't maintained anymore, but it still does the job really good. It has already given me useful information many times (e.g. what happens when you use an enhanced-for loop).

Have fun!
Kind regards,
Roel
 
Luca Cazzaniga
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jad was the missing brick for the building tests. Surely I'll improve my training..

Thanks again

Luca

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic