Stop overwriting each method in a lambda expression. There is no real benefit. If you have a regular method, you can call it a simple name without adding apply, testor similar. If you really need a function, you can still create a method reference using the operator ::.
, , API Java. :
static List<Node> getChilds(Node node, Predicate<Node> cond) {
NodeList nodeList = node.getChildNodes();
return IntStream.range(0, nodeList.getLength()).mapToObj(nodeList::item)
.filter(cond).collect(Collectors.toList());
}
Predicate s. , . .
Predicate<Node> isElement = node -> node.getNodeType() == Node.ELEMENT_NODE;
Function<Node,String> nodeName=Node::getNodeName;
Predicate<Node> both=isElement.and(nodeName.andThen("tag"::equals)::apply);
?
Predicate<Node> both=isElement.and(n->n.getNodeName().equals("tag"));
, , Node ELEMENT node "tag", , :
getChilds(document, n->"tag".equals(n.getNodeName()));
, , .