...
Code Block | ||
---|---|---|
| ||
class Overloader { public class Overloader { private static String display(List<?> l) { return ( l instanceof ArrayList ? "Arraylist" : (l instanceof LinkedList ? "LinkedList" : "List is not recognized") ); } public static void main(String[] args) { // Single ArrayList System.out.println(display(new ArrayList<Integer>())); List<?>[] invokeAll = new List<?>[] {new ArrayList<Integer>(), new LinkedList<String>(), new Vector<Integer>()}; for (List<?> i : invokeAll) { System.out.println(display(i)); } } } |
...
Appicability
Ambiguous uses of overloading can lead to unexpected results.
...
Guideline
...
Severity
...
Likelihood
...
Remediation Cost
...
Priority
...
Level
...
MET51-J
...
low
...
unlikely
...
high
...
P1
...
Automated Detection
Sound automated detection of violations is infeasible because it would require determination of programmer intent. Heuristic techniques may be useful.
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this guideline on the CERT website.
Bibliography
[API 20062011] Interface CollectionCollection<E>
[Bloch 2008] Item 41: Use overloading judiciously
[Tutorials 2010] Defining Methods
...