My question is in regard to the way Java handles String literals. It\'s quite clear from the Java Language Specs (JLS) that String literals are being implicitly interned - in ot
Casting to Object
is not allowed in a compile time constant expression. The only casts permitted are to String
and primitives. JLS (Java SE 7 edition) section 15.28:
> - Casts to primitive types and casts to type String
(There's actually a second reason. object
isn't final
so cannot possibly by considered a constant variable. "A variable of primitive type or type String
, that is final
and initialized with a compile-time constant expression (§15.28), is called a constant variable." -- section 4.12.4.)