...
Code Block | ||||
---|---|---|---|---|
| ||||
public class ListInspectorExample { public static void inspect(List<List<String>> l) { for (List<String> list : l) { for (String s : list) { // ClassCastException on 42 System.out.println(s); } } } public static void main(String[] args) { List<String> s = Arrays.asList("foo"); List i = Arrays.asList(42); // warning about raw types List<List<String>> l = new ArrayList<List<String>>(); l.add(s); l.add(i); // warning about unchecked convertion inspect(l); } } h2. |
Noncompliant
...
Code
...
Example
...
(Array
...
of
...
lists)
...
The
...
problem
...
persists
...
if
...
the
...
function
...
paramter
...
is
...
replaced
...
with
...
an
...
array
...
of
...
lists
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| =
| |
| ||||||
public class ListInspectorExample {=java} public static void inspect(List<String>[] l) { for (List<String> list : l) { for (String s : list) { // ClassCastException on 42 System.out.println(s); } } } public static void main(String[] args) { List<String> s = Arrays.asList("foo"); List i = Arrays.asList(42); // warning about raw types inspect(new List[] {s, i}); // warning about unchecked convertion } } h2. Noncompliant Code Example |
Noncompliant Code Example (Variadic
...
Arguments)
...
The
...
problem
...
persists
...
if
...
the
...
function
...
parameter
...
is
...
changed
...
to
...
a
...
variadic
...
argument
...
of
...
List<String>
...
.
...
During
...
type
...
erasure,
...
the
...
compiler
...
translates
...
this
...
to
...
a
...
single
...
array
...
of
...
objects.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| =
| |
| ||||||
public =java} class ListInspectorListInspectorExample { public static void inspect(List<String>... l) { for (List<String> list : l) { for (String s : list) { // ClassCastException on 42 System.out.println(s); } } } public static void main(String[] args) { List<String> s = Arrays.asList("foo"); List i = Arrays.asList(42); // warning about raw types inspect( s, i); // warning about variadic generic parameter } } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
public class ListInspectorListInspectorExample { public static void inspect(List<String>... l) { for (List<String> list : l) { for (String s : list) { // ClassCastException on 42 System.out.println(s); } } } public static void main(String[] args) { List<String> s = Arrays.asList("foo"); List<Integer> i = Arrays.asList(42); inspect( s, i); // improper argument types compiler error } } |
...