Note that public interface AllowedValue<T extends Class<? extends SystemValue>>
does not make much sense. The only valid type for T
would be Class<? extends SystemValue>
as the class Class
is final and can’t have subclasses. So you can replace it with interface AllowedValue<Class<? extends SystemValue>>
without any change in the semantic, but what you really mean (imho) is interface AllowedValue<T extends SystemValue>
. Don’t mess around with Class
in a type signature. The interface still might have methods referring to Class<T>
then.
public interface ValuesSystem {
public interface AllowedValue<T extends SystemValue>{};
AllowedValue<? extends SystemValue> getAllowedValue(Enum<?> id);
public <T extends SystemValue> T create
(AllowedValue<T> allowedClass, ValueData data);
}
Adapt the implementation accordingly, BasicAllowedValue
becomes
private class BasicAllowedValue<T extends SystemValue> implements AllowedValue<T>
Then your problem with the using code disappears.
BasicValueSystem bvs = new BasicValueSystem();
AllowedValue<? extends SystemValue> allowed = bvs
.getAllowedValue(BasicValueSystem.VALUES_ID.MODIFIER);
bvs.create(allowed, new ModifierValueData());
will compile.
Note that if AllowedValue
shall remain a marker interface without methods only, it is unnecessary, Class<T>
already fulfills this role. It will also work when doing it like this:
public interface ValuesSystem {
Class<? extends SystemValue> getAllowedValue(Enum<?> id);
public <T extends SystemValue> T create(Class<T> allowedClass, ValueData data);
}
and
BasicValueSystem bvs = new BasicValueSystem();
Class<? extends SystemValue> allowed = bvs
.getAllowedValue(BasicValueSystem.VALUES_ID.MODIFIER);
bvs.create(allowed, new ModifierValueData());