The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes strange thing about char. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "strange thing about char." Watch "strange thing about char." New topic

strange thing about char.

Yuan Ye
Ranch Hand

Joined: Mar 05, 2003
Posts: 172
Supposing we have following defination:
char c = 10;
int i = 20;
I understand why c=c+i can't be compiled. But why c+=i can be compiled? Please help.
Fahad Fahad

Joined: May 28, 2003
Posts: 1
Actually this is casting.
complier does explicit casting when using
this is equal to
c= char(c + i);
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1090
Similar vquestion has been posted before. Here's the url
Yi Meng
Ranch Hand

Joined: May 07, 2003
Posts: 270

c= char(c + i);

should be c=(char)(c+i);
For expressions like opt1+=opt2; they can always interpreted as:
where T is the type of opt1. This also applies to operators such as : -+, *=, /=, etc

Meng Yi
I agree. Here's the link:
subject: strange thing about char.
It's not a secret anymore!