Created
March 29, 2024 01:14
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 Example { | |
public static void main(String[] args) { | |
Map<Integer, String> treeMap = new TreeMap<>(); | |
treeMap.put(1, "하나"); | |
treeMap.put(2, "둘"); | |
treeMap.put(3, "셋"); | |
System.out.println("실패 전: " + treeMap); | |
try { | |
// ClassCastException 발생 시도 | |
treeMap.put(4, (String)(Object)new Integer(4)); // 임의로 ClassCastException 유발 | |
} catch (ClassCastException e) { | |
// 예외 처리 | |
System.out.println("ClassCastException occurred: " + e.getMessage()); | |
} | |
System.out.println("실패 후: " + treeMap); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment