Byte b = new Byte(10); //Compile error But if i do like this its ok byte b = 10; Byte by = new Byte(b); anyone pls explain why the compiler is reporting error in the first case even though the value passed is well within the range of byte and the constructor of Byte class takes byte value as parameter.
Byte b = new Byte(10); In this case I believe the 10 passed as a parameter is considered to be a literal, as such it is implicitly of type int (32 bit). The wrapper class Byte does not have a constructor that accepts an int and so you get a compiler error. Iain
Hi, All wrapper class constructors accept two types of constructor arguments, String and the corresponding primitive type (e.g. the wrapper type Short accepts String and short). Only exception to the rule are the wrapper classes Character, which accepts only the primitive type char, and Float which accepts double as well as String and float. Greetings, Gian Franco