Map<String, Object>을 이용해서 여러 개의 ArrayList<MyObject>들을 넘겨주게 된 경우가 있었다.
지금 다시 작업한다면 그럴 여지를 만들지 않겠지만,
value = map.get(key) 같은 형태로 map의 value를 가져오면 Unchecked cast warning이 발생한다.
@SuppressWarnings("unchecked")를 추가해주면 warning은 무시되지만
뭔가 찝찝하다고 생각되면 번거롭지만 다음과 같이 하면 된다.
value = map.get(key) 같은 형태로 map의 value를 가져오면 Unchecked cast warning이 발생한다.
@SuppressWarnings("unchecked")를 추가해주면 warning은 무시되지만
뭔가 찝찝하다고 생각되면 번거롭지만 다음과 같이 하면 된다.
This file contains 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
List<MyObject> arrayList = new ArrayList<>(); | |
if (resultMap.get("key") instanceof List) { | |
List list = (List) resultMap.get("key"); | |
for (Object item : list) { | |
if (item instanceof MyObject) { | |
arrayList.add((MyObject) item); | |
} | |
} | |
} |
java스럽게 복잡한데 속은 시원하다.