I am having some trouble grasping generics. I've read through Oracle's tutorial on generics and it doesn't seem to address my question. I also don't know what to search for in finding my answer.
Let's say that I have the following code:
public abstract class Buff<V> {
public V value;
{
public interface Buffable<V> {
public void buff(Buff<V extends Buff> buff);
}
public class DoubleBuff extends Buff<double> {
public double value;
}
public class DoubleBuffable implements Buffable<DoubleBuff> {
public void Buff(DoubleBuff buff) {
//implementation
}
}
I want to be able to create classes that inherit Buff and have the member "value," but specify value's type (See DoubleBuff). I also want to define classes that implement the buff method using an input parameter that is of a subtype of Buff.
DoubleBuffable is some class that implements Buffable, but expects an input of DoubleBuff and not StringBuff.
Am I expressing my generics correctly?