This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reference variable in Inner Class

 
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"?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic