What will be the result of compilation of the following code?

public class GenericClassReferences {
    public static void main(String[] args) {
        Class intClass = int.class;
        Class<Integer> genericIntClass = int.class; // 1
        genericIntClass = Integer.class;            // 2
        intClass = double.class;                    // 3
        genericIntClass = double.class;             // 4  
    }
}
Explanation
Class reference declared with non-generic type can hold a link to any Class object, but reference declared with a generic type can hold only a link to an object with declared type parameter. Syntax of type parameters make it possible for compiler to perform additional type-checking.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes