File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Reference variable in Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reference variable in Inner Class" Watch "Reference variable in Inner Class" New topic

Reference variable in Inner Class

ronnir paterl

Joined: Oct 18, 2007
Posts: 11

I had a doubt about final static fields in Inner classes.

According to the JLS,
Inner classes may not declare static members, unless they are compile-time constant fields

So my question is that why isn't object reference type (o1) considered to be compile-time constant field when used with final and static instead of just final?

class TLC{
class Inner{
//final static Object o1 = null;

Object o2 = null;
final Object o3 = null;

final static int j = 22;
int s = 4;

The is the error for the commented line

"The field o1 cannot be declared static; static fields can only be declared in static or top level types"

Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 378
Check the uncommented static members...

So we may have to raise the question "what are compile time constants"?

I agree. Here's the link:
subject: Reference variable in Inner Class
It's not a secret anymore!