File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help about wrapper class constructor

 
Peixiao Lin
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It seems I can not pass int value to Byte constructor except explicitly casting and using String? Well, if data type matters, why I can pass double value to Float constructor? please help me out.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, methods will automatically widen a primitive data type in order to match an expected argument type, but they will not narrow it (because this could result in a loss of precision). This automatic widening is called method-call conversion.

Note that a literal int value can be assigned to a narrower primitive type if it is within range. However, this narrowing is only for assignments -- not method arguments.


The Float constructor is a little unusual (compared to the other numeric wrappers) because it's overloaded to accept a float or a double. In the case of a double, the argument is converted to a float before wrapping.
[ October 17, 2004: Message edited by: marc weber ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic