• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

autoboxing: int to double

 
Jukka Nevalainen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21497
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jukka Nevalainen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your fast reply!

Regards,
rethab
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic