what is the difference between this two
Byte i1=new Byte(1);//complier error
byte b=1;//ok
my question is about assigning the value 1 to byte where 1 is int literal.
but when passing 1 to the Byte class constructor it gives error
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The value 1 is a literal of type integer. So you have the following situations:
Assigning the literal directly to a variable of type
bytewill cause an implicit conversion since it is obvious that the programmer wants a byte and not an int.The
Bytector takes abytevalue, the compiler complains since it can’t do an implicit conversion for method or ctor arguments.