🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #20004

Inner classes and inheritence

#20004
From: David B. McCaughan
Date: Wed, 12 Nov 1997 00:00
103 lines
3395 bytes

I've run into a problem with the JBuilder compiler with regard to
inheritance of inner classes, I thought I'd run it by the experts for
a second opinion :)  I do not suffer this problem using SUN's JDK, and
my understanding of how inner classes are implemented tells me this
should work.

My application is more involved, but this illustrates the problem---let's
say I have a class (testbase) with a member class (Inner) that is returned
by some method.  Now say I sub-class testbase (testsub), what I now want
is to override a method of the Inner member class.  So, I define a member
class, Inner, in testsub---that extends testbase.Inner.  In this class,
I override the method in question.

In trying to complie and run this with JBuilder, I get an error saying that
there is no constructor "testbase$Inner() in class testbase.inner".  I
assume this is a complaint that there is no "no-arguement" constructor in
the base class.  Now, my understanding of inner classes is that the compiler
modifies the constructors for inner classes so that they are passed a
reference to the enclosing instance--so probably true that there is not
a "no-arguement" constructor for testbase.Inner, but why should there be?
Even better, if I define a constructor for testsub.Inner which takes a
reference to the enclosing instance, then invoke the supeclass constructor
(which I believe is documented and legal Java 1.1 syntax for inner classes):

...
public Inner (testbase ref)
{
	ref.super();
}
...

it tells me that "testbase.Inner" is not an inner class!  Maybe I'm missing
something here.


Is this a problem JBuilder has with inheriting from inner classes?  Since
the redefinition of Inner effectively shadows the superclass definition,
I don't think there should be a problem with this (and the behaviour is
as expected with the JDK, as mentioned previously). 

Any comments or suggestions appreciated (my apologies if there are syntax
problems with what appears below, I'm typing it in from memory).

---
EG:
---

public class testbase
{
	// default constructor: public testbase() { super() };

	public Inner getinner()
	{
		return(new Inner());
	}

	protected class Inner
	{
		public Inner()
		{
			System.out.println("Inner class:");
			rest();
		}
		public void rest()
		{
			System.out.println("-> base");
		}
	}
}

public class testsub extends testbase
{
	// default constructor: public testsub() { super(); }

	protected class Inner extends testbase.Inner
	{
		public void rest()
		{
			System.out.println("-> base");
		}
	}
}

public class testmain
{
	public static void main(String args[])
	{
		testbase a = new testbase();
		testsub b = new testsub();

		a.getinner();
		b.getinner();
	}
}

Thanks,

--
David B. McCaughan                 | Biological Computation Project
davidb@cs.ualberta.ca              | Department of Computing Science
davidb@solo.psych.ualberta.ca      | University of Alberta, CANADA
Technical Details
Message-ID: <64b9td$rh14@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,b2ce247d9b9fa122,start
X-Google-Attributes: gidf74b3,public
From: davidb@solo.psych.ualberta.ca (David B. McCaughan)
Subject: Inner classes and inheritence
Date: 1997/11/12
Message-ID: <64b9td$rh14@forums.borland.com>
X-Deja-AN: 288796871
Organization: None
Newsgroups: borland.public.jbuilder.java.language