Created
April 4, 2017 06:00
-
-
Save hokkun-dayo/02366fd5184aa48ff73204e4f3effb25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class テスト { | |
@Data | |
static class Name { | |
String name; | |
} | |
private static <T> List<T> test1(Class<T> clazz) throws IOException { | |
val mapper = new ObjectMapper(); | |
return mapper.readValue("[{\"name\": \"hokuto\"}]", new TypeReference<List<T>>() {}); | |
} | |
@Test | |
public void test() throws IOException { | |
List<Name> t = test1(Name.class); | |
System.out.println(t); // OK! | |
t.forEach(System.out::println)); // java.lang.ClassCastException!!! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment