Trying to convert the this section of code to get rid of the lambda expressions so it'll be able to work in java 7
System.out.println(nicksGraph.findPath(nicksGraph.nodeWith(new Coordinate(0,0)), (a->a.getX()==3 && a.getY()==1), new PriorityQueue<Node<Coordinate>, Integer>(funcTotal)));
I've looked around but maybe I'm just not understanding it correctly.
In Java 8, a lambda expression is a substitute for an anonymous inner class that implements a functional interface. It looks like here you're using a
Predicate
, because the expression is aboolean
.The
Predicate
interface was introduced in Java 8, so you need to re-create it yourself. You will not be able to createdefault
orstatic
methods, so just keep the functional interface method.Then, replace the lambda expression with the anonymous class declaration.
Take a look at Retrolambda. It is a backport of Java 8's lambda expressions to Java 7, 6 and 5.
findPath requires a Predicate as second argument. You could replace the lambda with
But the main problem will simply be the availability of
Predicate
itself, since it's a java8 feature. this code won't run in java7, no matter if you use lambdas or not.