i have 2 different classes. One is a generic valueHolder, that can contain anything that extends number.
class ValueHolder<T extends number>{
private T currentValue;
//more functions, database logic, etc...
}
the other class is more complex, and has a “targetValue”. Also its parameterized like this:
class MoreComplexClass<T extends ValueHolder<?>>
private T valueHolder;
private XXX requiredValue;
//a lot more functions.
}
Is it “possible” to use the Type of the valueHolder for the requiredValue of the MoreComplexClass?
What i am trying to achieve is: Beeing able to compare currentValue and requiredValue with > == < Operators without casting and without loosing Typesafety. (Maybe i’m also thinking way to complex to achiee this)
the answer is YES, you can declare the complex class this way:
but since you are using the
Numberclass, you won’t be able to use those operators, you’ll need to use one of theXXXvalue()methods (i.e.:doubleValue(),longValue()) from theNumberclass to able to use those operators.