File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 19068
    
  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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: autoboxing: int to double