Is there a way to pass a generic Array as parameter

java

Solution

Java generic method which accepts a generic array.

public <T> void printArray(T[] array){
        for (T element: array){
            System.out.println(element);
        }
    }

The method which accepts generic list.

public <T> void printList(List<T> list){
      for (T element : list){
           System.out.println(element);
      }
}

Problem

My question is quite simple: I have the following method in my generic class (with type parameters A and B) ``` public void add(A elem, int pos, B[] assoc) ``` What I want to do is create a method ``` public void add(A elem, int pos) ``` which calls the upper method with a empty Array in assoc. So far I havnt found a solution, since Java doesnt allows to instantiate arrays of generic types.

Original source

Related problems