This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Inner classes question
- From: Norman Hendrich <hendrich at informatik dot uni-hamburg dot de>
- To: java at gcc dot gnu dot org
- Date: Fri, 4 Feb 2005 14:30:10 +0100 (CET)
- Subject: Inner classes question
- Reply-to: Norman Hendrich <hendrich at informatik dot uni-hamburg dot de>
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