The line
associations.put("test1",B::setBeta);
below does not compile. I'm not clear why it won't work since B extends A. Is there a way to make this work? I'm trying to build a map of method references from an inheritance family.
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
public enum Test {
ENUM0() {
@Override
public void init() {
associations.put("test0",A::setAlpha);
}
},
ENUM1() {
@Override
public void init() {
associations.put("test1",B::setBeta);
}
};
public abstract void init();
Map<String, BiConsumer<? extends A, String>> associations = new HashMap<>();
}
class A {
public String getAlpha() {
return alpha;
}
public void setAlpha(String alpha) {
this.alpha = alpha;
}
String alpha;
}
class B extends A {
public String getBeta() {
return beta;
}
public void setBeta(String beta) {
this.beta = beta;
}
String beta;
}