首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SonarQube违规Java8双函数要求

SonarQube违规Java8双函数要求
EN

Stack Overflow用户
提问于 2018-11-20 21:57:34
回答 1查看 272关注 0票数 2

我用一个方法声明定义了一个函数接口,并在另一个项目的类中实现了该方法。SonarQube违规是因为我正在重新定义Java8中已经提供的标准函数接口。

代码语言:javascript
复制
@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方法调用更改为双函数语法?

EN

回答 1

Stack Overflow用户

发布于 2018-11-20 22:37:08

这一冲突表明已经有一个函数接口可以解决您试图使用自定义接口实现的目的,即BiFunction

因此,在定义XYZService的方法makeRESTServiceGetCall的地方,可以简单地在代码中创建一个BiFunction,如下所示:

代码语言:javascript
复制
BiFunction<String, Integer, XYZProfile> xyzProfileBiFunction = (string, integer) -> {
    return xyzProfile; // the GET call implementation using 'string' &'integer'      
};

然后在调用方法makeRESTServiceGetCall的地方,您可以简单地apply上面的实现为:

代码语言:javascript
复制
XYZProfile xyzProfileNullPointer = xyzProfileBiFunction.apply("nullpointer", 0);
XYZProfile xyzProfileParth = xyzProfileBiFunction.apply("Parth", 1);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53394623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档