Having problem with casting in Java recently I have used TypeReference object of Jackson. The situation looked liked this:
List<myObject> listOfObjects = new ArrayList<myObject>();
listOfObjects = mapper.readValue(connection.getInputStream(), new ArrayList.class);
was throwing an exception that LinkedHashMap could not be cast into myObject. I understand now what was wrong with it after some helpful person on SO told me to use TypeReference. I replace second line with:
listOfObjects = mapper.readValue(connection.getInputStream(), new TypeReference<List<myObject>>(){});
and there is just one thing that I cannot (still...) understand here: what is the inner class for here ({}
)? I obviously don't know all use cases of inner classes so I could use a bit of explanation here. Thank you.