...
| Code Block | ||
|---|---|---|
| ||
public class Overloader {
private static String display(ArrayList<Integer>ArrayList<Integer> a) {
return "ArrayList""ArrayList";
}
private static String display(LinkedList<String>LinkedList<String> l) {
return "LinkedList""LinkedList";
}
private static String display(List<?>List<?> l) {
return ""List is not recognized"";
}
public static void main(String[] args) {
// Array of lists
List<?>List<?>[] invokeAll = new List<?>List<?>[] {new ArrayList<Integer>ArrayList<Integer>(),
new LinkedList<String>LinkedList<String>(), new Vector<Integer>Vector<Integer>()};
for(List<?>List<?> i : invokeAll) {
System.out.println(display(i));
}
}
} |
...
| Code Block | ||
|---|---|---|
| ||
class Overloader {
public class Overloader {
private static String display(List<?>List<?> l) {
return (l instanceof ArrayList ? "Arraylist""Arraylist" : (l instanceof LinkedList ? "LinkedList""LinkedList"
: ""List is not recognized""));
}
public static void main(String[] args) {
List<?>List<?>[] invokeAll = new List<?>List<?>[] {new ArrayList<Integer>ArrayList<Integer>(),
new LinkedList<String>LinkedList<String>(), new Vector<Integer>Vector<Integer>()};
for(List<?>List<?> i : invokeAll) {
System.out.println(display(i));
}
}
}
|
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
| Wiki Markup |
|---|
\[[API 06|AA. Java References#API 06]\] [Interface Collection|http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collection.html] \[[Bloch 08|AA. Java References#Bloch 08]\] Item 41: Use overloading judiciously |
...
MET32-J. Ensure that constructors do not call overridable methods 12. Methods (MET) MET34-J. Follow the general contract when implementing the compareTo method