char assignments - TechRepublic
General discussion
July 6, 2001 at 09:35 AM
steverichman

char assignments

by steverichman . Updated 24 years, 11 months ago

given the following:

public class CharTest {
public static void main (String args[ ])
{
char c = ‘c’;
char r = ‘r’;
c+=r;
c=c+r;
}
}

How come c+=r; compiles, yet c=c+r; doesn’t, complaining about a possible loss of precision by widening r to an int?
Isn’t the += operator just a shorthand notation?

This discussion is locked

All Comments