我知道我可以使用匿名方法或lambda表达式,例如:
master
但是我无法弄清楚是否可以使用常规委托(委托bool X(MyObject o)),我的尝试失败了。
即创建委托,将其设置为方法a,然后将委托实例作为谓词传递。
答案 0 :(得分:2)
出于兼容性的原因,即使其他委托的签名兼容,也必须显式实例化委托。记录的文档不是很好,请参见this question中的讨论。
(非常冗长)语法的示例执行此操作:
MockHttpServletRequest:
HTTP Method = POST
Request URI = /insert
Parameters = {}
Headers = {Content-Type=[application/json;charset=UTF-8], Accept=[application/json;charset=UTF-8]}
Body = {"bin":"123456", "json_full":"{'brand':'visa', 'type':'credit', 'country':'USA', 'issuer':'BigBank'}", "brand":"visa", "type":"credit", "country":"USA", "issuer":"BigBank", "newObject":"true", "new":"true", "createdAt":"18/08/2018 02:00:00 +0200", "updatedAt":"18/08/2018 02:00:00 +0200"}
Session Attrs = {}
Handler:
Type = com.xxxxx.binlookup.controller.BinInfoController
Method = public org.springframework.http.ResponseEntity<java.lang.Object> com.xxxxx.binlookup.controller.BinInfoController.insertBIN(com.xxxxx.binlookup.model.BinInfo,javax.servlet.http.HttpServletResponse) throws com.fasterxml.jackson.core.JsonProcessingException
Async:
Async started = false
Async result = null
Resolved Exception:
Type = null
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 201
Error message = null
Headers = {Content-Type=[application/json;charset=UTF-8]}
Content type = application/json;charset=UTF-8
Body = {"id":"123456","newObject":false,"new":false,"bin":"123456","json_full":"{'brand':'visa', 'type':'credit', 'country':'USA', 'issuer':'BigBank'}","brand":"visa","type":"credit","country":"USA","issuer":"BigBank","createdAt":"18/08/2018 02:00:00 +0200","updatedAt":"18/08/2018 02:00:00 +0200"}
Forwarded URL = null
Redirected URL = null
Cookies = []