what are the different ways to create an Arraylist and Hashmap in groovy

后端 未结 4 1618
逝去的感伤
逝去的感伤 2021-01-05 02:53

I have created an ArrayList like the following:

def list = new ArrayList()

But the codenarc report it is warning like following.

         


        
4条回答
  •  再見小時候
    2021-01-05 03:31

    Typical is:

    def list = []
    

    other options include

    def list = new ArrayList()
    def list = new ArrayList()
    List list = new ArrayList()
    def list = [] as ArrayList
    List list = [] as ArrayList
    

    and of course:

    List list = new ArrayList();
    

    Similar options exist for HashMap using [:].

提交回复
热议问题