Given:
2. import java.util.*; 3. public class Vinegar { 4. public static void main(String[] args) { 5. Set<Integer> mySet = new HashSet<Integer>(); 6. do1(mySet, "0"); do1(mySet, "a"); 7. do2(mySet, "0"); do2(mySet, "a"); 8. } //from ww w . j a v a2 s. c om 9. public static void do1(Set s, String st) { 10. s.add(st); 11. s.add(Integer.parseInt(st)); 12. } 13. public static void do2(Set<Integer> s, String st) { 14. s.add(st); 15. s.add(Integer.parseInt(st)); 16. } }
Which are true? (Choose all that apply.)
H:Note
D and G are correct.
It's legal to pass a generic collection to a method that's expecting a non-generic collection.
In do2(), the compiler knows that "s" can contain only Integers and that st is a String.
If this line of code is removed, the parseInt()
invocation will throw a NumberFormatException when it is passed "a".