CycleDetectedException needs to call Object#toString()
@@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Stack;
+import java.util.stream.Collectors;
/**
* Traverses a directed graph and if it contains any cycle, throw an exception.
@@ -76,7 +77,7 @@ public abstract class CyclicGraphDetector<N> {
public final List cycle;
public CycleDetectedException(List cycle) {
- super("Cycle detected: "+ String.join(" -> ", cycle));
+ super("Cycle detected: " + cycle.stream().map(Object::toString).collect(Collectors.joining(" -> ")));
this.cycle = cycle;
}
}
