Is there a way that I can pass a generic type to a generic class like
interface Wrapper<T, R> {}
interface Result<T, Wrapper<T, R>> {
R getResult();
}
Here Result takes Wrapper one of the type with type arguments T and R. getResult method in Result interface returns R.
What I did is below,
interface Result<T, W> {
<K> K getResult();
}
Is there a better way to do this in java.
You need a separate type argument for a Result interface. Something like this:
interface Result<T, R, W extends Wrapper<T, R>> {
R getResult();
}
Now you can use W inside the result to represent the Wrapper or T and R to represent wrapper components. It's possible though that W is completely unnecessary for you and having T and R is enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With