Java erasure with generic overloading (not overriding)

Either rename the methods, or use polymorphism: use an interface, and then either put the clawback code in the objects themselves, or use double-dispatch (depending on your design paradigm and taste).

With code in objects that would be:

public interface Clawbackable{
    void clawBack()
}


public class CommissionFacade
{

    public <T extends Clawbackable> void clawBack(Collection<T> objects)
    {
        for(T object: objects) 
        {
            object.clawBack();
        }           
    }
}

public class CommissionTrns implements Clawbackable {

    public void clawback(){
       // do clawback for commissions
    }
}

public class FinanceRequest implements Clawbackable {

    public void clawBack(){
      // do clwaback for FinanceRequest
    }

}

I prefer this approach, since I’m of the belief your domain should contain your logic; but I’m not fully aware of your exact wishes, so I’ll leave it up to you.

With a double dispatch, you would pass the “ClawbackHandler” to the clawback method, and on the handler call the appropriate method depending on the type.

Leave a Comment