The problem of java generics

    public static void printObjects(List<List<?>> args) {

    }

    public static void main(String[] args) {
        List<List<String>> list = new ArrayList<>();
        printObjects(list);
    }

now you want List < list is there any way to do this?

Mar.01,2021

try using syntactic types such as < T >

.

import java.util.*;

public class TestTemp {

public static <T> void printObjects(List<List<T>> args) {

}

public static void main(String[] args) {
    List<List<String>> list = new ArrayList<>();
    printObjects(list);
}

}

Note to declare that this is a template method < T > void.

in front of the corresponding method.
Menu