Is it possible to add variable number of generic parameters in class definition?
Ex:
public class Test<E,T,U...>
And the exact number of generic parameters to be defined while building the instance of the object.
Apparently you want to be able to make Test take multiple parameters of different types in the form of varargs.
VarArgs are actually being passed as an Array but you can't have an array with different types of objects in it.
However, Can't we instead take a single parameter and that parameter type holds each of the individual "parameters" that needs to be used.
class TypedInstance<T>{
Class<T> type;
T instance;
}
Or
Different classes for each set of parameters you want to use. Then just pass that class as a param.
class MultiTypedInstanceType1<T, R>{
public R doSomething(T t){ .... }
}
class MultiTypedInstanceType2<T, R, P>{
public R doSomething(T t, P p){ .... }
}
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