Creating instance list of different objects

前端 未结 7 1602
自闭症患者
自闭症患者 2021-02-04 08:17

I\'m tring to create an arraylist of different class instances. How can I create a list without defining a class type? ()

List

        
7条回答
  •  耶瑟儿~
    2021-02-04 09:16

    How can I create a list without defining a class type? ()

    If I'm reading this correctly, you just want to avoid having to specify the type, correct?

    In Java 7, you can do

    List list = new ArrayList<>();
    

    but any of the other alternatives being discussed are just going to sacrifice type safety.

提交回复
热议问题