Generics in Java, Merge method

后端 未结 1 402
北荒
北荒 2021-01-25 23:18

I have to create a Merge method to merge together two lists (Array-Based Lists). My method works, but now I have to change my method to generics. This is my method without gener

1条回答
  •  猫巷女王i
    2021-01-25 23:52

    Assuming you have declared > at the class level, remove it on the method:

    class OrderedArrayList1 > {
      public OrderedArrayList1 merge(OrderedArrayList1 list2) {
        ...
      }
    }
    

    Otherwise, you're defining a different type variable which just happens to have the same name, hence the slightly cryptic "T cannot be converted to T" message.

    0 讨论(0)
提交回复
热议问题