Method definition as
myMethod(Object... obj){}
allows you to use an arbitrary number and types of parameters.
I would like to use generics to strictly define the number and types of parameters.
For example, suppose the aforementioned myMethod(Object...) is a method in a class called MyClass and MyClass , which can be created by default by the 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>();
therefore, the above type definitions specify the number and types of parameters allowed when calling myMethod() :
instance1.myMethod(1, 2, "test"); instance2.myMethod("one", "two", 1, 2);
The question arises: how to define MyClass in such a way as to allow any number of type parameters?
Any advice would be appreciated.