Genericifiying some code

Hi all,
I have 5 classes that depend on each other for providing a few services and recently, I tried genericifying them and im quite happy with the result. Except that for some reason, it wont compile and I haven’t got a clue what syntax error i have made. Im sure its something to do with extends/super keywords, but im not sure:

I have this SuperInterface that most of the objects inherit from. The SuperInterfaceView is the view to the data stored inside the SuperInterface :


public interface SuperInterface {
	
	public SuperInterfaceView<? super SuperInterface> getSuperInterfaceView();

}


public class SuperInterfaceView<T extends SuperInterface> {
	
	public void doStuff(T stuff) {
		
	}

}

I have another class that creates the SuperInterfaceView depending on certain characteristics outside of the data, this is called a Creator:


public abstract class Creator {
	
	public static Creator getCreator() {
		return null;
	}
	
	public abstract SuperInterfaceView<? super SuperInterface> getSuperInterfaceView( Class<? super SuperInterface> clazz );

}

A simple implementor of SuperInterface that uses the Creator is:


public class Implementor implements SuperInterface {

	public SuperInterfaceView< ? super SuperInterface> getSuperInterfaceView() {
		return Creator.getCreator().getSuperInterfaceView( this.getClass() );
	}

}

Now the last class isn’t really needed for the above to compile without problems, but its necessary in the sense that if you get the above working, this class breaks, if you get this class fine, the Implementor breaks, they both need to be satisfied:


public class SuperInterfaceViewDistributor {
	
	public void doStuff(SuperInterface face) {
		face.getSuperInterfaceView().doStuff( face );
	}

}

Eclipse complains in Implementor that:

Any ideas whats going on here?

DP

Javac 6.0 tells me:


getSuperInterfaceView(java.lang.Class<? super SuperInterface>) in
 Creator cannot be applied to (java.lang.Class<capture#674 of ? extends Implementor>)
      return Creator.getCreator().getSuperInterfaceView( this.getClass() );

So appearantly they are not as equal as Eclipse thinks they are.

I tried just about anything, but couldn’t get a working version, without changing the whole structure.

The whole problem is “this.getClass()”, but “((SuperInterface)this).getClass()” threw some error too, while I thought that should do the trick.

Reading through the “Java Generics Tutorial” I grew 2 grey hairs.

I can change the architecture if you have any other ideas…

What really annoyed me was that this.getClass() does extend Implementor, and Implement is super to this.getClass() on both cases…Maybe im just understanding the sepcs wrong.

DP

public interface SuperInterface {
	
	public SuperInterfaceView<? super SuperInterface> getSuperInterfaceView();

}

do you have any idea what that ? is suppose to adapt? should look in it’s kristall ball and guess it’s implementation?

public interface SuperInterface {
	
	public <Type extends SuperInterface> SuperInterfaceView<Type> getSuperInterfaceView() {

        }

}

Unkown Type != Unkown Type

<?> != <?>