Originally posted by jay vas:
Hi I have a question that has been stumping for about 5 hours !
I want to extend a generic, abstract class...
I cant figure out how to do so, however, in such a
way that the inherited method has a strongly typed
parameter. Ive made an example that can be tested pasted
easily into eclipse
class MyExample
{
static abstract class GenericAbstract <A extends Object>
{
public abstract void doSomething(A a);
}
static class A { }
static class B extends A { }
/** Why cant I simply extend the generic abstract by
* concretely declaring B ? Also - why is it that
doSomething does not override properly ? Isnt that
the point of generics - to allow dynamic definition
of types ? If so - it should let me override by extension.
*
*/
static class ClassThatWontCompile <B> extends GenericAbstract
{
public void doSomething(B b)
{
}
}
}
I think you are just mixing the type parameter used in the declaration of GenericAbstract and ClassThatWontCompile with class A and B respectively.
Your declaration of GenericAbstract is :
Here A is not the nested class A. Rather its just a type parameter.
Similary in the declaration of ClassThatWontCompile:
Type parameter B is not the nested class B. Rather agaian its a type parameter. You can use anything here X or Y etc.
When you actually use your class, then you need to provide the type argument, which is in your case nested class A and B.
Is this you are looking for?
Naseem