How to create java.lang.Class with type parameter that is also typed?

generics, java

Solution

I would go for:

@SuppressWarnings("unchecked")
Class<List<String>> klass = (Class<List<String>>)((Class<?>) List.class);

And you do not need an instance of a the class for this type of cast.

Problem

What to put on place of ??? in the following code so it would work? ``` import java.util.List; public class Generic { private static class Foo<T> { Foo(Class<T> clazz) { assert clazz != null; } } public static void main(String[] args) { Class<List<String>> x = ???; Foo<List<String>> t = new Foo<List<String>>(x); } } ```

Original source