soap - Replace Anonymous Inner Class By Lambda. How does this work? -
while sending soap message, wanted add custom headers did below;
jaxbelement<configurationresponse> jaxbelementresponse = (jaxbelement<configurationresponse>) getwebservicetemplate() .marshalsendandreceive(urltosend, new objectfactory().createconfigurationrequest(request), new webservicemessagecallback() { @override public void dowithmessage(webservicemessage message) throws ioexception, transformerexception { saajsoapmessage soapmessage = (saajsoapmessage) message; soapheaderelement id = soapmessage.getsoapheader().addheaderelement(new qname(uri, localpart, prefix)); id.settext(text); } });
but "netbeans" tell me can use lambda expr. if change, like,
jaxbelement<configurationresponse> jaxbelementresponse = (jaxbelement<configurationresponse>) getwebservicetemplate() .marshalsendandreceive(urltosend, new objectfactory().createconfigurationrequest(request), (webservicemessage message) -> { saajsoapmessage soapmessage = (saajsoapmessage) message; soapheaderelement id = soapmessage.getsoapheader().addheaderelement(new qname(uri, localpart, prefix)); id.settext(text); });
are both same? if yes, how works?
a lambda expression syntactical sugar on anonymous class. lambda can used ever type functional interface, interface declares 1 abstract method. lambda expression provides implementation of single method.
for case webservicemessagecallback functional interface. has 1 abstract method: dowithmessage(...). lambda expression created provides implementation of method.
Comments
Post a Comment