This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
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: 430
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.
subject: About the primitive type char
Similar Threads
problem in if condition
Marcus Green tutorial question
KM Book -Section3.3 (Narrowing conversion between char and short
What's the difference "c=c+1" vs "c+=1"