Passing in “any” class type into a java method

后端 未结 3 2026
我寻月下人不归
我寻月下人不归 2021-01-26 11:21

Okay say I have a class:

public class ExampleClass() {
    public void exampleClassMethod(ArrayList abcdefg> arrList) {
        ....
             


        
3条回答
  •  时光取名叫无心
    2021-01-26 11:58

    Use List to accept any List object in the method.

    public void exampleClassMethod2(List custClassArg) {
        ....
    }
    
    
    

    use List instead of ArrayList as it give more flexibility.

    Also you can use List if all the other customClasses extends from a base type.

    提交回复
    热议问题