This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes autoboxing: int to double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "autoboxing: int to double" Watch "autoboxing: int to double" New topic
Author

autoboxing: int to double

Jukka Nevalainen
Greenhorn

Joined: Dec 14, 2009
Posts: 9
Hi there

The Question is probably not that easy, but nor it's complex. Here it is:

I can easily convert like this:
double d = 44;

But why is it no possible like that:
Double d = 44;
What about autoboxing? Java says: Cannot convert from int to Double. WTF?

Thanks for your help,
rethab

@Edit: I know it's possible like that: Double d = 44D;
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18532
    
  40

Jukka Nevalainen wrote:Double d = 44;
What about autoboxing? Java says: Cannot convert from int to Double. WTF?


See section 5.2 of the Java Language Specification. An implicit cast from int to double, followed by boxing to Double, is not allowed.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jukka Nevalainen
Greenhorn

Joined: Dec 14, 2009
Posts: 9
Thank you for your fast reply!

Regards,
rethab
 
 
subject: autoboxing: int to double
 
Similar Threads
conversion from String to any data type
Converting Strings to ints and other impracticalities
Wrapper Assignments from ExamLab
Is-A Relationship and Autoboxing
Converting double to int.