Overloading Java function with List<> parameter

前端 未结 6 1280
猫巷女王i
猫巷女王i 2021-02-02 15:19

I have 2 classes

public class Customer{
  ...
  public String getCustomerNumber();
  ...
}

public class Applicant{
   ....
   private Customer c;
   public Cust         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-02 15:37

    Use array instead.

    public void processCustomerNumbers(Customer[] custList)
    ...
    
    public void processCustomerNumbers(Applicant[] appList)
    ...
    

    When you try to call these methods with a list, convert the list to array:

    List customers;
    List applicants;
    ...
    processCustomerNumbers(customers.toArray(new Customer[]{});
    processCustomerNumbers(applicants.toArray(new Applicant[]{});
    

提交回复
热议问题