Which lines in the following code will cause a compilation error?

01: import java.util.*;
02: public class TestClass {    
03:     public static void main(String[] args) {
04:           List<Number> list = new ArrayList<Integer>(); 
05:           list.add(1);                                                    
06:           list.add(1.2);                      
07:           list.add(new Integer());                      
08:           list.add(new Integer("5"));   
09:      }
10: }        
Explanation
Line 4: covariance doesn't work with generic types, except if bounds are involved. Line 7: You should always pass a value to the Integer constructor

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback