Dynamic initialization of ArrayList

后端 未结 3 1971
借酒劲吻你
借酒劲吻你 2020-12-29 11:04

Normally if we want to initialize a generic non-primitive ArrayList we do this

ArrayList arrayList = new ArrayList();
<         


        
3条回答
  •  粉色の甜心
    2020-12-29 11:29

    This works:

    private void getModel(){
       ArrayList arrayList = new ArrayList();
    }
    
    
    

    I mean, it is unclear what you are trying to do. Generics is purely compile-timem, to perform compile-time type checking. Therefore, if the type parameter is not known at compile time, it would be useless.

    提交回复
    热议问题