Creating instance list of different objects

前端 未结 7 1482
自闭症患者
自闭症患者 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:07

    List anyObject = new ArrayList();

    or

    List anyObject = new ArrayList();

    now anyObject can hold objects of any type.

    use instanceof to know what kind of object it is.

    提交回复
    热议问题