malat
malat

Reputation: 12510

Extending class with generic parameter

I need to derive from the following class:

public abstract class MyTool<VIEW extends MyView>
  implements LookupListener, MouseListener, MouseMotionListener, KeyListener {}

The following does not work:

public abstract class MySubTool<VIEW> extends MyTool<VIEW> {}

Thanks !

Upvotes: 3

Views: 479

Answers (2)

Buhake Sindi
Buhake Sindi

Reputation: 89209

This should:

public abstract class MySubTool<VIEW extends MyView> extends MyTool<VIEW> {}

Upvotes: 1

Vivien Barousse
Vivien Barousse

Reputation: 20895

The compiler in MySubTool as no way of knowing that VIEW in MySubTool is a subclass of MyView, you have to specify it again:

public abstract class MySubTool<VIEW extends MyView> extends MyTool<VIEW> {}

Upvotes: 3

Related Questions