Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reference variable in Inner Class  RSS feed

 
ronnir paterl
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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"



Thanks
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the uncommented static members...

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

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!