How to replace generic type with concrete type when inheriting?

Hi,

Let's assume we have a generified container class

publicclass Container<T>{

public T getElement(){...}

publicvoid setElement(T element){...}

}

Now there is the need for a new specialized container class which inherits from the generic one. For this specialized class I would like to omit the generics completely for its users - something like:

publicclass SpecializedContainer<"T=SpecializedType">extends Container<T>{

public SpecializedElement getElement(){...}

publicvoid setElement(SpecializedElement element){...}

}

That means, I should be able to use that class as follows:

SpecializedContainer c =new SpecializedContainer();

SpecializedElement e = c.getElement();

Any ideas if/how this is possible?

Thanks, Hans

[1580 byte] By [HansNaltea] at [2007-10-2 22:03:33]
# 1
public class SpecializedContainer extends Container<SpecializedType> { ...}
dannyyatesa at 2007-7-14 1:20:03 > top of Java-index,Core,Core APIs...
# 2
Thanks a lot!
HansNaltea at 2007-7-14 1:20:03 > top of Java-index,Core,Core APIs...
# 3

> > public class SpecializedContainer extends

> Container<SpecializedType> {

>

But now you're screwed if you want to specialize this type, yes?

public class ReallySpecializedContainer extends SpecializedContainer /* oops; note you can't specify ReallySpecializedType here! */ {

}

...?

ljnelsona at 2007-7-14 1:20:03 > top of Java-index,Core,Core APIs...
# 4

Nope.

public class SpecializedContainer<T extends SpecializedType> extends SpecializedContainer<T> {

// ... or the other way round - I haven't tried this in my IDE...

}

So now you still need to specify a concrete type when declaring a SpecializedContainer, but that type must be SpecializedType or a descendant. Your SpecializedContainer can now perform operations on T as if it were a SpecializedType

dannyyatesa at 2007-7-14 1:20:03 > top of Java-index,Core,Core APIs...