aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes b*=b1 vs b=b*b1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "b*=b1 vs b=b*b1" Watch "b*=b1 vs b=b*b1" New topic
Author

b*=b1 vs b=b*b1

Jeremy Chan
Greenhorn

Joined: Mar 28, 2001
Posts: 12
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

Joined: Jul 26, 2001
Posts: 2
I want to know how to explain it. Who can tell us? thanks!


Helping you means helping me
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

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).]


Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
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
 
subject: b*=b1 vs b=b*b1