What will happen during the following code execution?

import java.util.*;
public class Test {
    public static void main(String[] args) {
        List a = new ArrayList<Double>();// 4
        a.add("1.5");// 5
        List<Double> b = new ArrayList();// 6
        b.add("1.5");// 7
        System.out.println(a + " " + b);
Compilation error occurs in the seventh line, because only elements of Double type and derived from it can be added to the "b" collection. Elements of any type can be added to "a" collection, so parameterized type Double is stepped up to Object.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Зареєструйся Зараз
або Підпишись на майбутні тести