Link to home
Start Free TrialLog in
Avatar of falmon
falmon

asked on

Java char value assignments

Hi,

I am porting a Java project which makes some strange assignments of int values in a function.  I have been Googling this for a while but have not figured it out.

The char c is being passed to the setX function which has a single int parameter.  So why has the original coder used a char instead of int?  The 'else' segment seems to assign an invalid unicode character to the char.  I don't know what c = '\210' does (decimal 210 is Ò).

Sorry the code fragment is so terse, there's not a lot of surrounding code to post.
char c;
if (xPos < 100) {
  c = '\210';
} 
else {
  c = '\uFFF8';
}
obj.setX(c);
 
 
// this is the definition of obj.setX
public void setX(int i)

Open in new window

Avatar of josepvalls
josepvalls
Flag of United States of America image

Java will automatically cast the int value of a character.
Are you sure the int value of '\210' is what you want?
Avatar of falmon
falmon

ASKER

Well - I am trying to work out what the code does so that I can replicate its behavior in AS3.  So I'm not sure that I want the int value of '\210'.  I am still baffled as to why he decided to create a char, assign it odd values, and then pass it into a function which will cast it as int.  The char isn't used elsewhere.

My assumption was that since "char c = '\uFFF8';" will create a single Unicode character (http://www.fileformat.info/info/unicode/char/fff8/index.htm - possibly... it doesn't even seem to be a valid char) his '\210' assignment would perhaps assign a Unicode char by decimal value?

I guess my question is - what values would I expect as the integer argument to setX for each part of the conditional, given the char values set, and is there any clear reason that the original coder decided to use a char in this way?
ASKER CERTIFIED SOLUTION
Avatar of josepvalls
josepvalls
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of falmon

ASKER

OK, that's very useful in terms of how the casting works and basically answers the question!!
Never would have expected those int castings coming from a PHP/JS/AS background.