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

b*=b1 vs b=b*b1

 
Jeremy Chan
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you can see
Will the following code compile ?
1. byte b=2;
2. byte b1=3;
3. b*=b1;
The Answer is Yes
But
Will the following code compile ?
1. byte b=2;
2. byte b1=3;
3. b=b*b1;
The Answer is No , explicit cast from int to byte needed
Why?
b*=b1; does not equal to b=b*b1 ?



 
irisly
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know how to explain it. Who can tell us? thanks!
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chan,
byte b,b1=1; b *= b1;
Here b *= b1 means b = (byte)b*b1; implicit casting is happening here (in ur case-1), which is not happening in the second case.
------------------
azaman
[This message has been edited by Ashik uzzaman (edited August 20, 2001).]
 
Ragu Sivaraman
Ranch Hand
Posts: 464
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeremy Chan:
As you can see
Will the following code compile ?
1. byte b=2;
2. byte b1=3;
3. b*=b1;
The Answer is Yes
But
Will the following code compile ?
1. byte b=2;
2. byte b1=3;
3. b=b*b1;
The Answer is No , explicit cast from int to byte needed
Why?
b*=b1; does not equal to b=b*b1 ?




b*=b1;
It is Arithmetic Extended Assignment Operation
Implicit Casting is OK
b=b*b1;
Binary Operation with simple assignment
Implicit casting not applicable

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic