java 8 个关于 jsonpath 库的 lambda 技术问题
java 8 lambda tech question for jsonpath library
我正在查找有关 lambda 的信息,但我找不到与以下函数类似的信息。它属于 class org.springframework.test.web.servlet.result.JsonPathResultMatchers ,并且 ResultMatcher 是一个@FunctionalInterface,结果类型为 MvcResult 和 jsonPathHelper.doesNotExist return void
public ResultMatcher doesNotExist() {
return result -> jsonPathHelper.doesNotExist(getContent(result));
}
我打电话给上面一位通过
jsonPath("$._embedded" ).doesNotExist()
我完全不知道:
if jsonPathHelper.doesNotExist return void 那么为什么不存在 return ResultMatcher.
Class有什么类似于结果,这个参数是从哪里来的?
谢谢
您代码中的 lambda:
result -> jsonPathHelper.doesNotExist(getContent(result));
只是 ResultMatcher
的表示,因为它是 FunctionalInterface
。你可以这样看:
public ResultMatcher doesNotExist() {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
jsonPathHelper.doesNotExist(getContent(result)); // returns void
}
};
}
if jsonPathHelper.doesNotExist return void then why doesNotExist
return ResultMatcher
您的方法 doesNotExist
,只是 returns 本身的功能接口,此后可用于调用其 match
功能。请注意,调用也会返回 void
.
Class has anything similar to result, where is this argument come
from?
如果您查看上面的匿名 class,使用 lambda 表示,result
成为 ResultMatcher
实现中 match
方法的参数。
因此,当您真正希望访问此实现时(或通常 ResultMatcher
),您可以按如下方式调用该方法(简化初始化):
ResultMatcher resultMatcher = doesNotExist(); // your method returns here
MvcResult result = new MvcResult(); // some MvcResult object
resultMatcher.match(result); // actual invocation
我正在查找有关 lambda 的信息,但我找不到与以下函数类似的信息。它属于 class org.springframework.test.web.servlet.result.JsonPathResultMatchers ,并且 ResultMatcher 是一个@FunctionalInterface,结果类型为 MvcResult 和 jsonPathHelper.doesNotExist return void
public ResultMatcher doesNotExist() {
return result -> jsonPathHelper.doesNotExist(getContent(result));
}
我打电话给上面一位通过
jsonPath("$._embedded" ).doesNotExist()
我完全不知道:
if jsonPathHelper.doesNotExist return void 那么为什么不存在 return ResultMatcher.
Class有什么类似于结果,这个参数是从哪里来的?
谢谢
您代码中的 lambda:
result -> jsonPathHelper.doesNotExist(getContent(result));
只是 ResultMatcher
的表示,因为它是 FunctionalInterface
。你可以这样看:
public ResultMatcher doesNotExist() {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
jsonPathHelper.doesNotExist(getContent(result)); // returns void
}
};
}
if jsonPathHelper.doesNotExist return void then why doesNotExist return ResultMatcher
您的方法 doesNotExist
,只是 returns 本身的功能接口,此后可用于调用其 match
功能。请注意,调用也会返回 void
.
Class has anything similar to result, where is this argument come from?
如果您查看上面的匿名 class,使用 lambda 表示,result
成为 ResultMatcher
实现中 match
方法的参数。
因此,当您真正希望访问此实现时(或通常 ResultMatcher
),您可以按如下方式调用该方法(简化初始化):
ResultMatcher resultMatcher = doesNotExist(); // your method returns here
MvcResult result = new MvcResult(); // some MvcResult object
resultMatcher.match(result); // actual invocation