About Question enthuware.ocajp.i.v7.2.1313 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
JQuirke

About Question enthuware.ocajp.i.v7.2.1313 :

Post by JQuirke »

Here are the rules:
The type of the Expression must be char, byte, short, or int, or a compile-time error occurs.
All of the following must be true, or a compile-time error will result:
This was changed in Java 7

The switch statement compares the String object in its expression with the expressions associated with each case label as if it were using the String.equals method; consequently, the comparison of String objects in switch statements is case sensitive. The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.

source: http://docs.oracle.com/javase/7/docs/te ... witch.html

Just so a person doesn't automatically tick the does not compile box when then see a string.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1313 :

Post by admin »

You are right. String should be mentioned as well. This has now been updated.
thank you for your feedback!

mehtapra
Posts: 4
Joined: Sat Oct 13, 2012 2:00 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1313 :

Post by mehtapra »

Just to add , Wrapper Classes for char, byte, short, int (i.e. Character, Bye, Short, and Integer) are also allowed as an argument in the switch statements as they are unboxed to the corresponding primitive types.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests