Defining a method as
myMethod(Object... obj){}
allows arbitrary number and types of parameters to be used.
I'd love to use generics for strict definition of the number and types of parameters.
For example, Let's assume that the above mentioned myMethod(Object...)
is a method in a class named MyClass
and MyClass
can be instantiated by default constructor.
I need to define instances in a way similar to this:
MyClass<Integer, Integer, String> instance1 = new MyClass<Integer, Integer, String>();
MyClass<String, String, Integer, Integer> instance2 = new MyClass<String, String, Integer, Integer>();
so the type definitions above will set the number and types of parameters allowed on calls to myMethod()
:
instance1.myMethod(1, 2, "test");
instance2.myMethod("one", "two", 1, 2);
The question is: How to define MyClass
in such a way that will allow any number of type parameters?
Any advice will be appreciated.