Originally posted by Sathiya Sun:
Sorry I was wrong, it is "static member variable" not "static instance variable".
From you reponse I understood that, Enums, are not compile time constants.
so, what it means is..
class MyInnerClass {
static string string; // Ok
enum MyEnum {}; // Not Ok - Because it is not a compile time constant.
}
Am I right...
Thanks for explaining !
Sathiya
15.28 Constant Expression
ConstantExpression:
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).
Compile-time constant expressions are used in case labels in switch statements (�14.11) and have a special significance for assignment conversion (�5.2). Compile-time constants of type String are always "interned" so as to share unique instances, using the method String.intern.
A compile-time constant expression is always treated as FP-strict (�15.4), even if it occurs in a context where a non-constant expression would not be considered to be FP-strict.
Examples of constant expressions:
true
(short)(1*2*3*4*5*6)
Integer.MAX_VALUE / 2
2.0 * Math.PI
"The integer " + Long.MAX_VALUE + " is mighty big."
Originally posted by Sathiya Sun:
I confused myself with the Nested Top level class with other inner class types(regular, anonymous and local member inner class).
The bottom line is that, I can have "static members" declared within Nested Top level, but not in other non-top level classes(unless it is compile time constant), this explains why I cannot have enums declared with the regular inner clasess (not static or top level).
ested Top Level class allows for static member declarations irrespective of whether it is a "Compile Time Constant" or not.
Thanks Ken for explaining.
- Sathiya
Originally posted by Sathiya Sun:
Ken, your last post help solve a lot of mystery around this nested and inner clasess.
I came to know about the "Nested Top level" when I was searching for answers.
For Instance:
Developer forum
May be I have misinterpreted. Thanks for the patient explanation all along.
Sathiya
A nested class is any class whose declaration occurs within the body of another class or interface. A top level class is a class that is not a nested class.
Originally posted by Sathiya Sun:
Ken, after you pointing out, I started to look for the JLS as my ultimate reference.
I think it is wise move to start using JLS from now on.
Thanks
Sathiya
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
So, when you encounter the term "top-level nested cass", be aware that it was the official term for a while, but isn't any more. For about six years, I think.
Now if you encounter someone talking about "static inner classes" - such terminology was never correct, and those people really have no excuse.
Originally posted by Sathiya Sun:
Should I follow the JLS (third edition). Now, I am bit paranoid about JLS, with all these facts.
Or is there any good book for J2SE 5 at an advanced level, that covers all these topics. To this day I haven't followed any book.
Help me guys.
"To do good, you actually have to do something." -- Yvon Chouinard
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|