Inner classes question

Norman Hendrich hendrich@informatik.uni-hamburg.de
Sun Feb 6 12:08:00 GMT 2005


Hello all,

I just found the time to test another gcj snapshot (gcc-4.0-20050130)
with my apps. While I still have problems with the gcj AWT (see next 
postings), the compiler itself works great.

However, gcj complains about a few of my classes that can be simplified
down to the following two (very similar) cases:


import java.awt.*;

public class SSS extends Canvas {
  int state = 0;

  public class Selector extends Dialog {
    public Selector( Frame parent ) {
      super( parent );
    }

    public void foo() {
      state = 42;
    }
  }
}


SSS.java:12: error: Can't access private field 'java.awt.Window.state' from 
'SSS$Selector'.
         state = 42;




And a similar case:


import java.awt.*;
import javax.swing.*;

public class TTT {
  private Color background;

  public class JImageCanvas extends JComponent {
    public void foo( Graphics g ) {
      g.setColor( background ); 
    }
  }
}

TTT.java:9: error: Can't access package-private field 
'java.awt.Component.background' from 'TTT$JImageCanvas'.
         g.setColor( background ); 
         
         
Admittedly, rewriting the classes with better variable names or using
getter/setter-methods seems the best solution. Still, all of javac, jikes,
and Eclipse compile those classes (against JDK 1.4.2) without problems,
resolving the variable name to the name in the outer parent class.

Who is right here?

- Norman         



More information about the Java mailing list