假设我有两个方法
例如,我希望能够这样做:
void chargeToIndividual(int amount, int account)
和void chargeToCompany(int amount, int account)
。假设我还有另一个名为void processSale(String item, Customer c)
的方法。我该如何才能将chargeToIndividual
或chargeToCompany
作为参数传递给processSale
,并如何调用它?例如,我希望能够这样做:
if(isIndividual(someCustomer))
{
processSale(anItem, someCustomer, chargeToIndividual)
}
else if(isCompany(someCustomer))
{
processSale(anItem, someCustomer, chargeToCustomer)
}
那么在processSale()
函数内,我应该如何调用chargeToIndividual
或者chargeToCustomer()
函数呢?