gcj/358: private method overloading when inner class extends its enclosing class

bryce@albatross.co.nz bryce@albatross.co.nz
Sat Oct 21 19:30:00 GMT 2000


>Number:         358
>Category:       gcj
>Synopsis:       private method overloading when inner class extends its enclosing class
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    apbianco
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 21 19:30:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Bryce McKinlay
>Release:        gcc version 2.97 20001015 (experimental)
>Organization:
>Environment:
*
>Description:
If an inner class extends its enclosing class and
"overloads" a private method declared in the enclosing class,
which method gets called?

In class files compiled with javac, it depends on the 
declared type of the variable (see test code below):

$ java InnerPvt
InnerPvt
A
A
InnerPvt
A
InnerPvt
InnerPvt

With gcj however, the outer method is always called from 
the outer class (but calls from the inner class behave
correctly):

$ ./ip
InnerPvt
InnerPvt
InnerPvt
InnerPvt
A
InnerPvt
InnerPvt
>How-To-Repeat:
class InnerPvt
{
  private void a()
  {
    System.out.println ("InnerPvt");
  }

  public static void main(String[] args)
  {
    InnerPvt ip = new InnerPvt().new A();
    ip.a();
    InnerPvt.A ipa = new InnerPvt().new A();
    ipa.a();
    ipa = (InnerPvt.A) ip;
    ipa.a();    
    ip = ipa;
    ip.a();
    ipa.b();    
  }

  class A extends InnerPvt
  {
    private void a()
    {
      System.out.println ("A");    
    }
    
    void b()
    {      
      this.a();
      InnerPvt ip = this;
      ip.a();
      InnerPvt.this.a();
    }
  }
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the Java-prs mailing list