2020-06-30 12:47:33 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
public class S1944 {
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
List<String> list = (List<String>) getAttributes(); // Noncompliant; List<Integer> return by getAttributes() is not be casted to List<String>
|
|
|
|
String s = list.get(0); // java.lang.ClassCastException will be raised here
|
|
|
|
}
|
|
|
|
|
|
|
|
private static List<?> getAttributes() {
|
|
|
|
List<Integer> result = new ArrayList<>();
|
|
|
|
result.add(0);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
----
|
|
|
|
public class S1944 {
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
List<Integer> list = (List<Integer>) getAttributes(); // Compliant
|
|
|
|
String s = String.valueOf(list.get(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static List<?> getAttributes() {
|
|
|
|
List<Integer> result = new ArrayList<>();
|
|
|
|
result.add(0);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2021-09-17 13:50:03 +02:00
|
|
|
include::../see.adoc[]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::message.adoc[]
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|