This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Iimplicit cast Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Iimplicit cast" Watch "Iimplicit cast" New topic

Iimplicit cast

Fox Hu
Ranch Hand

Joined: Jan 23, 2003
Posts: 49
byte b=127;
byte c=126;
byte d=b-c;
In the third line the compiler complains .
It seams that the result is casted to int implicitly when two number calculate, but why?
And are there any other cases do the implicit cast appears ?
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
but it is compiled!

a beginner in java
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610

[Blog] [Blogroll] [My Reviews] My Linked In
Paula Jiang

Joined: Feb 15, 2003
Posts: 15
From Kathy/Bert 's book, page 148-149: "the result of an expression involving anything int-sized or smaller is always an int. In other words, add two bytes together and you'll get an int."
So the compiler will complain that it can't convert int to byte, you need to explicit case to byte.

SCJP2 1.4 (96%) SCWCD(96%)
I agree. Here's the link:
subject: Iimplicit cast
jQuery in Action, 3rd edition