【小家面试】JavaSE基础面试题---大杂烩

说在前面

此博文旨在搜集一些JavaSE基础部分的经典面试题,希望能达到一针见血,通过面试题来达到让大家记忆深刻的目的。
持续连载中。。。

案例

1、请补全下面代码,达到所需输出的效果
 public static void main(String[] args) throws Exception {
        List<Integer> list = new ArrayList<>();
        list.add(1);

        //请在此处补全代码

        System.out.println(list); //期望输出为:[1, a, 2, b]
    }
2、判断下面输出什么内容?

输出内容eg:
java.lang.Number
java.lang.Integer
等类似的

public static void main(String[] args) throws NoSuchFieldException {
        Field id = Son.class.getField("id");
        System.out.println(id.getType()); 
    }

    class Son extends BaseEntity<Integer> {
        public String name;
    }

    class BaseEntity<PK extends Number> {
        public PK id;
    }
 public static void main(String[] args) throws NoSuchFieldException {
        Field id = Son.class.getField("id");
        System.out.println(id.getType()); 
    }

    class Son extends BaseEntity<Integer> {
        public String id;
        public String name;
    }

    class BaseEntity<PK extends Number> {
        public PK id;
    }

猜你喜欢

转载自blog.csdn.net/f641385712/article/details/81713172