This is the mail archive of the
java-prs@gcc.gnu.org
mailing list for the Java project.
java/5850: resolving inherited member variables
- From: goran at kirra dot net
- To: gcc-gnats at gcc dot gnu dot org
- Date: Wed, 6 Mar 2002 13:41:01 +0100
- Subject: java/5850: resolving inherited member variables
>Number: 5850
>Category: java
>Synopsis: resolving inherited member variables with same name works poorly
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Wed Mar 06 04:46:03 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:
>Release: 3.2 20020305 (experimental)
>Organization:
>Environment:
System: Linux cm-linux.lla.sema.se 2.4.17 #8 mån feb 18 17:25:46 CET 2002 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure i686-pc-linux-gnu --prefix=/usr/local/gcc --enable-threads --enable-languages=c++,java
>Description:
In an inner class inherits a variable ad to outer class inherits one
with the same name GCJ can't pick the right one
--------------------------- snip ----------------------------------------------
bash-2.05a$ gcj x.java y.java y1.java
x.java: In class `x$x1':
x.java: In method `x$x1.getId()':
x.java:6: Can't make a static reference to nonstatic variable `id' in class `x$x1'.
return new Integer(id);
^
1 error
--------------------------- snip ----------------------------------------------
Jikes/JDK resolvs this right.
>How-To-Repeat:
compile this 3 files, the error is in evident in file x.java
--------------------------- snip (x.java) -------------------------------------
public class x extends y
{
private static class x1 extends y1 {
public Integer getId() {
return new Integer(id); // this.id works with JDK and gcj
}
}
public static void main(String[] args)
{
x1 t = new x1();
System.out.println(t.getId());
}
}
--------------------------- snip (y.java) -------------------------------------
public class y
{
protected final int id = 1;
}
--------------------------- snip (y1.java) ------------------------------------
public class y1
{
protected final int id = 2;
}
--------------------------- snip ----------------------------------------------
>Fix:
workaround: this.id instead of just id fix it.
>Release-Note:
>Audit-Trail:
>Unformatted: