The problem is that you can initialize the local var in the subclass in this
situation since you
have a handle to them but you cannot  initialize the outer class instance viable
your self since you cannot get
a handle to it.


If you hand a  instance variable

String myString

in the   Parent2  class

You could initialize it like

  public void callFooBar(){
        myString="I set this "
        .......
    }

I suspect this is what your referring too.
The bug is you have no way to init the outer class variable since even though it
exists
you don't have a handle Someone else mentioned that is is set in the byte code and
should be since the outer class is already initialized
so the JVM has a handle to its instance. But you don't have access to this since its
generated code.


I guess I wasn't clear on the Bug its not the initialization In my first post I said
I understood what was happening
but that they don't provide access to the outer class viable via a method call akin
to super.
 InnerOuter.this = ?????

I think Object should be enhcaned to provide acess to this viarlbe via
getOuterInstance()
This method would return null unless your and inner class.



So I think its a bug.


As far is to why I'm reporting it here.  Well for political reasons.

Javasoft has this nice little disclaimer on there bug tracking page..

http://java.sun.com/cgi-bin/bugreport.cgi

Before you start:

This web page is for reporting bugs in products distributed on java.sun.com.

.............

I find it a bit offensive that Sun is pushing NT on me.
But this is a diffrent issue so don't respond to my rant below.

Technically Linux users cannot even make bug reports or requests.
Even though I've accepted the "Open" SCL I'm excluded.
I don't care much for Sun's caste system even India is getting away from it.
It seems linux users  are members of the new  high tech untouchables caste as in
definition 2a.

>From Websters on nextstep snif ...
 1:
one of the hereditary social classes in Hinduism that restrict the occupation of
their members and their association with the members of other castes
2a:
a division of society based on differences of wealth, inherited rank or privilege,
profession, or occupation
 b:
the position conferred by caste standing
3:
a system of rigid social stratification characterized by hereditary status,
endogamy, and social barriers sanctioned by custom, law, or religion
 4:
 a specialized form (as the soldier or worker of an ant) of a polymorphic social
insect that carries out a particular function in the colony




Mike

Not a political bone in my body : )

Rick Kiss wrote:

> Hi Michael,
>
> I suppose the other folks that didn't respond were, rightly, concerned that the
> question is not a Linux-Java issue but I will try to addess it anyway since you
> brought it back up.
>
> Your example, if I remember right from when I took the Java Certification test
> last year, is a varient of a question on the test.  If you built a slightly more
> extended test you would have noticed that your call to "callFooBar()" in Parent2
> from Parent1 occured before Parent2 was initialized.  This means you were trying
> to talk to "InnerOuter.this" before the inner class had an initialized pointer to
> it.
>
> This isn't a bug but part of the language spec. Since it will always be there one
> has to plan for constructor issues like it.
>
> I suspect that language design issues fit better in Java programmer groups.
>
> Have fun,
>
> Rick Kiss
>
> Slightly more informative example.
> ----------------------------------------------------------------
> class Parent1 {
>
>     public Parent1(){
>      callFooBar();
>     }
>
>     public void callFooBar(){
>         System.out.println(" Parent1 callFoobar");
>     }
> }
>
> public class InnerOuter {
>
>     // Inner class
>     class Parent2 extends Parent1 {
>      public Parent2() {
>             callFooBar();
>         }
>
>         public void callFooBar(){
>          System.out.println("Parent2 callFooBar - - - " + this);
>
>             try {
>                 System.out.println(" Parent2 Foobar " + InnerOuter.this);
>             } catch (Exception e) {
>                 System.out.println(" Parent2 Foobar " + e);
>             }
>             if (InnerOuter.this == null)
>                 System.out.println(" InnerOuter.this == null - class not
> initialized");
>             else
>                 testOut(this);
>         }
>     }
>
>     public InnerOuter() {
>      testOut(this);
>      Parent2 p2 = new Parent2();
>     }
>
>     public void testOut(Object ob) {
>        System.out.println("TEST OUT: "+ob);
>     }
>
>     public static void main( String[] args ) {
>      InnerOuter test1 = new InnerOuter();
>     }
> }
> ----------------------------------------------------------------
>
> Michael Emmel wrote:
>
> > To extend my own question I think this is a bug since thre is no way
> > for a programmer to intialize the enclsing instance variable.
> > I think that Object should have a methos added.
> >
> > getEnclosingInstance()
> >
> > Then you coud do ..
> >
> >        public void callFooBar(){
> >             if( OuterClass.this == null ) {
> >                     OuterClass.this = getEnclosingInstance();
> >             }
> >             System.out.println(" Parent2 Foobar " +OuterClass.this);
> >         }
> >
> > My point being that the subclass should alwas be able to access its enclosing
> > class.
> > The probelm is thre is no way for a prgrammer to init the instance variable
> > that I know of.
> >
> > This does not work either
> >
> > class Parent2 extends Parent1 {
> >             Parent2( OuterClass outer ) {
> >                 outer.super();
> >             }
> >            public void callFooBar(){
> >                System.out.println(" Parent2 Foobar " +OuterClass.this);
> >            }
> >
> >        }
> >
> > Anyway I think it is a bug.
> >
> > Michael Emmel wrote:
> >
> > > This generates the following output ..
> > >
> > > Parent2 Foobar null
> > >
> > > I understand why but  it  compiles and fails at runtime.
> > > Thus if you subclass a class with and inner class any method used is the
> > > parents consturctor cannont
> > > acces the Outer class.
> > >
> > > Of course I may be doing something stupid but I know the  instance.super
> > > stuff and this is the referse case.
> > > It seems a bit pathalogical and also it compiles fine even though it
> > > will never run.
> > > The null pointer excetion if you access  OuterClass.this is not exactly
> > > helpful either.
> > >
> > > Any thoughts ??
> > >
> > > Mike
> > >
> > > class Parent1 {
> > >
> > >     public Parent1(){
> > >         callFooBar();
> > >     }
> > >
> > >     public void callFooBar(){
> > >         System.out.println(" Parent1 Foobar");
> > >     }
> > >
> > > }
> > >
> > > public class OuterClass {
> > >
> > >     class Parent2 extends Parent1 {
> > >
> > >         public void callFooBar(){
> > >             System.out.println(" Parent2 Foobar " +OuterClass.this);
> > >         }
> > >
> > >     }
> > >
> > >     public OuterClass() {
> > >
> > >         Parent2 p2 = new Parent2();
> > >     }
> > >
> > >     public static void main( String[] args ) {
> > >             OuterClass test1 = new OuterClass();
> > >
> > >     }
> > >
> > > }
> > >
> > > ----------------------------------------------------------------------
> > > To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> > > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
> >
> > ----------------------------------------------------------------------
> > To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
>
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to