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.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты