angelika ann wrote:My compiler says that lines 1, 3 and 4 must be removed.
Maduranga Liyanage wrote:
angelika ann wrote:My compiler says that lines 1, 3 and 4 must be removed.
Yes. That is correct.
My problem is why 128 is an error when it can be put into an int.
Also whether unboxing doesnt work in like 4.
Cheers.
What I want to know is, if my switch statement is a byte, does all my case statements need to be bytes too? or be able to assigned to a byte (without losing precision)?
• Every case constant expression associated with a switch statement must be
assignable (§5.2) to the type of the switch Expression.
• No switch label is null.
• No two of the case constant expressions associated with a switch statement
may have the same value.
• At most one default label may be associated with the same switch state-
ment.
All code in my posts, unless a source is explicitly mentioned, is my own.
plus the switch statement (only) needs to be assignment compatible to int (not the case staements
The type of the Expression must be char, byte, short, int, Character, Byte, Short, Integer, or an enum type (§8.9), or a compile-time error occurs.
SCJP 1.6
SCWCD 1.5 (Preparing...)
Every case constant expression associated with a switch statement must be
assignable (§5.2) to the type of the switch Expression.
A compile-time constant expression is an expression denoting a value of primitive type or a String that does not complete abruptly and is composed using only the following:
Literals of primitive type and literals of type String (§3.10.5)
Casts to primitive types and casts to type String
The unary operators +, -, ~, and ! (but not ++ or --)
The multiplicative operators *, /, and %
The additive operators + and -
The shift operators <<, >>, and >>>
The relational operators <, <=, >, and >= (but not instanceof)
The equality operators == and !=
The bitwise and logical operators &, ^, and |
The conditional-and operator && and the conditional-or operator ||
The ternary conditional operator ? :
Parenthesized expressions whose contained expression is a constant expression.
Simple names that refer to constant variables (§4.12.4).
Qualified names of the form TypeName . Identifier that refer to constant variables (§4.12.4).
SCJP 1.6
SCWCD 1.5 (Preparing...)
Maduranga Liyanage wrote: But its confusing why I cannot get Integer to work despite being mentioned in the specification
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Oracle certified JPA Developer (1Z0-898),Oracle certified Java 8 Programmer I (1Z0-808), Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I, CIW Certified Ecommerce specialist
Abhay Agarwal wrote:
line -- final Integer IntObj = new Integer(2); says that IntObj is final reference but its value can change.
All code in my posts, unless a source is explicitly mentioned, is my own.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |