File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About the primitive type char Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About the primitive type char" Watch "About the primitive type char" New topic
Author

About the primitive type char

Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 433
Why this can compile ok

and this failed?


To be or not to be. It's a question.
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138
According to JLS

In addition, if the expression is a constant expression (�15.28) of type byte, short, char or int :

A narrowing primitive conversion may be used if the type of the variable is byte, short, or char, and the value of the constant expression is representable in the type of the variable.


that means the c must be a constant expression
use,



to compile the second one.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About the primitive type char