Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending class with generic parameter

Tags:

java

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 !

like image 206
malat Avatar asked Jan 27 '26 06:01

malat


2 Answers

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> {}
like image 199
Vivien Barousse Avatar answered Jan 28 '26 18:01

Vivien Barousse


This should:

public abstract class MySubTool<VIEW extends MyView> extends MyTool<VIEW> {}
like image 43
Buhake Sindi Avatar answered Jan 28 '26 20:01

Buhake Sindi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!