my dog learned polymorphism
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

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About the primitive type char" Watch "About the primitive type char" New topic

About the primitive type char

Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 434
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

to compile the second one.
I agree. Here's the link:
subject: About the primitive type char
It's not a secret anymore!