• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting "int" type cast to lower precision "char" type in Parasoft JTEST  RSS feed

 
sonali duggi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below code I am using to typecast int to char.
char escapeValue = (char)0;
char cha = (char) 10;
escapeValue = (char)(escapeValue * cha); // Here am getting the above error.

I have 38 similar issues in my workspace. please help me
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the first two casts are unnecessary because you are providing a compile‑time constant whose value is in the range for a char. You can do arithmetic on chars, but beware of multiplication and division; they are very unlikely to produce a sensible result. You are obtaining the null character from 0 × 10.

The warning you are receiving is from JTEST; it compiles without error or warning on ordinary openJDK7_51 even if the first two casts are removed. Obviously whoever programmed JTEST thought you should not be casting 0 × 10 to a char.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!