This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes help in initializing wrapper objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "help in initializing wrapper objects" Watch "help in initializing wrapper objects" New topic

help in initializing wrapper objects

Sugantha Jeevankumar
Ranch Hand

Joined: Jun 06, 2007
Posts: 93
In the following code snippet, the compiler shows error on both of the bolded lines

Why does this happen? But when I call the constructor using "new Double(9)" it works fine...Please help
Thanks in Advance.

SCJP 5.0
Lucas Lech

Joined: Dec 10, 2007
Posts: 23
Sometimes it can be useful to actually check the compiler error

first line gives you 'cannot convert from int to Double'
second one gives 'cannot convert from float to Double'

try this one:

Double myDouble = 9d;

[ December 11, 2007: Message edited by: Lucas Lech ]
jQuery in Action, 3rd edition
subject: help in initializing wrapper objects
It's not a secret anymore!