Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java declaring a variable which implements an interface

Tags:

java

interface

this is my first question I ask here so I might do some things wrong.

I wish to declare a variable which I know is of a class which implements an interface.

private <T extends Executable> T algorithm;

This was my attempt to achieve the goal

like image 308
MattiasDC Avatar asked Dec 15 '22 09:12

MattiasDC


1 Answers

You don't have to use generics for that. The following will work for any sub-class / implementation of Executable:

private Executable algorithm;
like image 63
buritos Avatar answered Jan 01 '23 06:01

buritos