interface ConfigService {
ConfigValue getConfig(ConfigProperty configProperty);
}
interface ConfigValue<T>{
T getValue();
}
interface ConfigProperty<T>{
ConfigurationProperty<Boolean> ENABLE_SEC_EVAL_LOG = new
ConfigurationProperty.Default<>("ENABLE_SEC_EVAL_LOG");
ConfigurationProperty<Integer> SEC_EVAL_LOG_THRESHOLD = new
ConfigurationProperty.Default<>("SEC_EVAL_LOG_THRESHOLD");
class Default<T> implements ConfigProperty<T> {
private final String name;
private Default(final String name) {
this.name = name;
}
@Override
public String getName() {
return this.name;
}
}
}
public class A {
public static void main() {
ConfigurationValue cv = getConfiguration(ConfigurationProperty.ENABLE_SEC_EVAL_LOG);
Boolean abc = cv.getConfigValue();
}
}
I want to force getValue
to return Boolean if the ConfigProperty type is Boolean.
I want to force getValue
to return String if the ConfigProperty type is String.
What am I doing wrong here? Am I not using the generics in the correct way?