Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > referring to static fields of enclosing class from static inner class?

Reply
Thread Tools

referring to static fields of enclosing class from static inner class?

 
 
bugbear
Guest
Posts: n/a
 
      08-22-2006
Is there a way to name the "outer" class?
I understand the Outer is NOT a super-class
of inner. Is inner "almost" stand alone
or is there an eaqsy way (other than Outer.a)
that the method f() can refer to the
string a from Outer?

BugBear


class Outer {
public static final String a = "a";
static class inner {
String f() {
return a; // doesn't work.
return super.a; // doesn't work
return Outer.a; // works but is not what I want
}
}

}
 
Reply With Quote
 
 
 
 
bugbear
Guest
Posts: n/a
 
      08-22-2006
bugbear wrote:
> Is there a way to name the "outer" class?
> I understand the Outer is NOT a super-class
> of inner. Is inner "almost" stand alone
> or is there an eaqsy way (other than Outer.a)
> that the method f() can refer to the
> string a from Outer?
>
> BugBear
>
>
> class Outer {
> public static final String a = "a";
> static class inner {
> String f() {
> return a; // doesn't work.
> return super.a; // doesn't work
> return Outer.a; // works but is not what I want
> }
> }
>
> }


Colour me an idiot. "return a;" DOES work.

BugBear
 
Reply With Quote
 
 
 
 
Ingo R. Homann
Guest
Posts: n/a
 
      08-22-2006
bugbear wrote:
> Colour me an idiot.


OK - where is the paint?

SCNR,
Ingo

 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      08-22-2006

"bugbear" <bugbear@trim_papermule.co.uk_trim> wrote in message
news:44eaf94e$0$2694$(E-Mail Removed)...
> bugbear wrote:
>> Is there a way to name the "outer" class?
>> I understand the Outer is NOT a super-class
>> of inner. Is inner "almost" stand alone
>> or is there an eaqsy way (other than Outer.a)
>> that the method f() can refer to the
>> string a from Outer?
>>
>> BugBear
>>
>>
>> class Outer {
>> public static final String a = "a";
>> static class inner {
>> String f() {
>> return a; // doesn't work.
>> return super.a; // doesn't work
>> return Outer.a; // works but is not what I want
>> }
>> }
>>
>> }

>
> Colour me an idiot. "return a;" DOES work.


It will work if there's no "closer" a (parameter, local variable, field in
inner) obscuring it. Suppose something was obscuring the static field; can
you expalin why "Outer.a" isn't the "right" way to refer to it?


 
Reply With Quote
 
bugbear
Guest
Posts: n/a
 
      08-23-2006
Mike Schilling wrote:
>
>
> It will work if there's no "closer" a (parameter, local variable, field in
> inner) obscuring it. Suppose something was obscuring the static field; can
> you expalin why "Outer.a" isn't the "right" way to refer to it?


In my instance because the out class had a long name,
and I wanted to ue "rather a lot" of fields from
it.

Just typing convenience and line length.

Or (if you will) ease and elegance of expression.

BugBear
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Referring to method in enclosing class Richard Everhart Ruby 5 01-31-2008 11:00 PM
Referencing enclosing class from inner class Jonathan Java 3 07-31-2006 12:30 PM
Enclosing class instance availability during inner class initialization Stanimir Stamenkov Java 4 07-14-2006 01:13 PM
Re: How does an inner class (non-static) refer to members of it's enclosing class? Jayaram Java 0 07-18-2003 05:03 PM
Re: How does an inner class (non-static) refer to members of it's enclosing class? Tor Iver Wilhelmsen Java 0 07-18-2003 08:41 AM



Advertisments