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

后端 未结 4 1741
逝去的感伤
逝去的感伤 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:34

    You can do:

    def list = []               // Default is ArrayList
    def list = [] as ArrayList
    ArrayList list = []
    

    And again, for HashMap:

    HashMap map = [:]
    def map = [:] as HashMap
    

    The default in this case is a LinkedHashMap:

    def map = [:] 
    

提交回复
热议问题