Hello Jose, Can you explain it in more detail. JLS says that declaration of a member needs to appear before it is used only if it is an instance field of a class or interface. So here s is the member and it is used to call the method msg even before it is declared. But what doed it mean when JLS says usage is not on the left hand side of the arguement. Thank you Pallavi
posted 17 years ago
184.108.40.206 Restrictions on the use of Fields during Initialization The declaration of a member needs to appear before it is used only if the member is an instance (respectively static) field of a class or interface C and all of the following conditions hold: * The usage occurs in an instance (respectively static) variable initializer of C or in an instance (respectively static) initializer of C. * The usage is not on the left hand side of an assignment. * C is the innermost class or interface enclosing the usage. A compile-time error occurs if any of the three requirements above are not met.
It compiles ok. "s" is in the left hand side of an assignment. The use of "s" occurs within an instance (block) initializer.
Compiler error, forwarding reference is not allowed because "s" is on the right of the assignment.
SCJP2. Please Indent your code using UBB Code
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad: