Java erasure with generic overloading (not overriding)

前端 未结 2 577
旧时难觅i
旧时难觅i 2020-11-27 07:26

I have FinanceRequests and CommisionTransactions in my domain. If I have a list of FinanceRequests each FinanceRequest could contain multiple CommisionTransactions that need

2条回答
  •  孤街浪徒
    2020-11-27 08:05

    I think your best option is to simply name the method differently.

    public void clawBackFinReqs(Collection financeRequestList) {
    
    }
    
    public void clawBackComTrans(Collection commissionTrnsList) {
    
    }
    

    In fact, it's not too bad, since you don't get anything extra out of having the same name on them.

    Keep in mind, that the JVM will not decide which method to call at runtime. As opposed to virtual methods / method overriding resolution of overloaded methods are done at compile time. The Java Tutorials on method overloading even points out that "Overloaded methods should be used sparingly...".

提交回复
热议问题