I have some Java code similar to:
public class Thing {
private IPolicy policy;
public Thing(IPolicy policy) {
this.policy = policy;
}
public void doSomething() {
this.policy.execute();
}
}
My question is: is it possible to do this with generics rather than passing the policy to the constructor? I think this means I want it to end up as
public class Thing<T extends IPolicy>
but I'm not that up on generics.
My motivations are: 1) it would make more sense to me for my program for this to be part of the type and not be involved with the constructor (which has other more relevant things to do) and 2) I'm trying to learn generics.