Skip to content

Instantly share code, notes, and snippets.

@hokkun-dayo
Created April 4, 2017 06:00
Show Gist options
  • Save hokkun-dayo/02366fd5184aa48ff73204e4f3effb25 to your computer and use it in GitHub Desktop.
Save hokkun-dayo/02366fd5184aa48ff73204e4f3effb25 to your computer and use it in GitHub Desktop.
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