Why is the difference in declaration of generic Lists?

前端 未结 2 542
被撕碎了的回忆
被撕碎了的回忆 2021-02-13 05:20

I want to decare two Lists: First is a list of Integers. I decare it as:

  List ints= Arrays.asList(1,2,3);

It works fine.

2条回答
  •  花落未央
    2021-02-13 06:10

    Use this works perfect

    List objs = Arrays.asList(10,20.32,"test");
    
    System.out.println(objs);
    

    Output: [10, 20.32, test]

提交回复
热议问题