首页 > 解决方案 > 通过泛型在java中制作泛型接口

问题描述

我正在使用下面的界面,如下所示

public interface ZaestrorardRule {

    Map<String, List<MMTM>> exceute(String jobCode, String Plientlo) throws AaestroRardNetworkException;

}

然后有一个实现它的类,如下所示

public class AaestroRardBusinessRNFRuleImpl implements ZaestrorardRule {

    public Map<String, List<MMTM>> exceute(String jobCode, String Plientlo) throws AaestroRardNetworkException {

    }

}

现在假设我正在开发除上面显示的 ZaestrorardRule 之外的其他一些功能,它与 ZaestrorardRule 具有相同的功能,然后我必须创建一个单独的界面,如下所示

public interface WWaestrorardRule {

    Map<String, List<MMTM>> exceute(String jobCode, String Plientlo) throws AaestroRardNetworkException;

}

我的问题是我可以在接口中使用泛型,以便在接口结构固定时会有一个接口。

标签: javagenerics

解决方案


在Java中,我们可以扩展接口。您可以创建父接口:

public interface GenericRule {

    Map<String, List<MMTM>> exceute(String jobCode, String Plientlo) throws AaestroRardNetworkException;

}

像这样改变你的两个界面

public interface ZaestrorardRule extends GenericRule {

}

public interface WWaestrorardRule extends GenericRule {

}

推荐阅读