- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVarargsTest.java
More file actions
Latest commit
28 lines (21 loc) · 833 Bytes
/
Copy pathVarargsTest.java
File metadata and controls
28 lines (21 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
packagebasic;
importorg.junit.jupiter.api.Assertions;
importorg.junit.jupiter.api.Test;
importjava.util.Arrays;
importjava.util.Collections;
importjava.util.List;
publicclassVarargsTest {
@Test
publicvoidheap_pollution_test() {
//String one = firstOfFirst(Arrays.asList("one", "two"), Collections.emptyList());
Assertions.assertThrows(ClassCastException.class, () -> {firstOfFirst(Arrays.asList("one", "two"), Collections.emptyList());});
//기대하던 결과
//Assertions.assertEquals("one", one);
}
publicstaticStringfirstOfFirst(List<String>... strings) {
List<Integer> ints = Collections.singletonList(42);
Object[] objects = strings;
objects[0] = ints; // Hepa pollution
returnstrings[0].get(0); //ClassCast Exception
}
}