我用一个方法声明定义了一个函数接口,并在另一个项目的类中实现了该方法。SonarQube违规是因为我正在重新定义Java8中已经提供的标准函数接口。
@FunctionalInterface
/*access modifier*/ interface XYZService {
XYZProfile makeRESTServiceGetCall(String str, Integer id);
}
"Drop this interface in favor of "java.util.function.BiFunction<String,Integer,XYZProfile>"Drop this interface in favor of "java.util.function.BiFunction<String,Integer,XYZProfile>"REST服务GET调用只接受输入并返回XYZProfile。一般来说,项目结构需要使用接口,但是为了解决声纳冲突,我是否应该删除'interface',并将makeRESTServiceGetCall方法调用更改为双函数语法?
发布于 2018-11-20 22:37:08
这一冲突表明已经有一个函数接口可以解决您试图使用自定义接口实现的目的,即BiFunction。
因此,在定义XYZService的方法makeRESTServiceGetCall的地方,可以简单地在代码中创建一个BiFunction,如下所示:
BiFunction<String, Integer, XYZProfile> xyzProfileBiFunction = (string, integer) -> {
return xyzProfile; // the GET call implementation using 'string' &'integer'
};然后在调用方法makeRESTServiceGetCall的地方,您可以简单地apply上面的实现为:
XYZProfile xyzProfileNullPointer = xyzProfileBiFunction.apply("nullpointer", 0);
XYZProfile xyzProfileParth = xyzProfileBiFunction.apply("Parth", 1);https://stackoverflow.com/questions/53394623
复制相似问题