What is the result of compilation and execution of the following code?

public class Test {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        list.add(100);
        list.add(200);
        list.add(300);
        list.add(200);
        Set<Number> set = new HashSet<Integer>(list);
        System.out.println(set.size());
        } 
}
Explanation
Generic class HashSet<Integer> is not a subtype of Set<Number>
More here https://docs.oracle.com/javase/tutorial/java/generics/inheritance.html

Следи за CodeGalaxy

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

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