| AW: a problem compiling a Java 5 project with generics | AW: a problem compiling a Java 5 project with generics 2006-10-18 - By Scot P. Floess
Peter:
Point well taken. The problem here, I think, is that the inner class has access to everything defined in the outer class (this includes the declaration of the generic). Of course, javac comes in and does some creative compiling to make that possible. Personally, I strive very hard to avoid inner classes...or at the very least declare them as "private static final" inner classes (thus avoiding the whole "has access to member variables" issues). In most cases the inner classes make fine stand-alone versions...
Peter Reilly wrote: > The original code may be slightly incorrect (my understanding > of java generics is not high). > > Test1.java is defined as: > public class Test1<T extends Base> { > public class Inner1 { > protected T v; > public Inner1(T v) {this.v = v;} > public T getV() {return this.v;} > } > public Inner1 getInner(T v) {return new Inner1(v);} > } > > It could also be defined as: > package test; > public class Test1<T extends Base> { > public class Inner1<T extends Base> { > protected T v; > public Inner1(T v) {this.v = v;} > public T getV() {return this.v;} > } > public Inner1 getInner(T v) {return new Inner1<T>(v);} > } > > The second definition makes the Inner1 class explictlly be a generic > class, > Test2 then is: > package test; > public class Test2<T extends Base> extends Test1<T> { > public class Inner2 extends Inner1<T> { > public Inner2(T v) {super(v);} > } > } > > and Test3 is unchanged. > > In this case, compilation works fine. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@(protected) > For additional commands, e-mail: user-help@(protected) > >
-- Scot P. Floess 27 Lake Royale Louisburg, NC 27549
252-478-8087 (Home) 919-754-4592 (Work)
Chief Architect JPlate http://sourceforge.net/projects/jplate Chief Architect JavaPIM http://sourceforge.net/projects/javapim
--------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@(protected) For additional commands, e-mail: user-help@(protected)
|
|
 |