-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
8, 25
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
System.getProperty("java.version") = 23.0.1
Eclipse Adoptium jdk-23.0.1.11-hotspot
A DESCRIPTION OF THE PROBLEM :
Getting syntax error for a perfectly valid declaration of Comparator. The syntax error is obtained while entering code in Eclipse 2024-09 or in VSCode jupyter notebook with Java kernel. The declaration involves Comparator.comparingInt(n -> f(n)).thenComparingInt(n -> h(n))
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
class Node {
public int depth;
public Node(int depth) {
this.depth = depth;
}
}
class Trial {
public static int f(Node n) {
return n.depth;
}
public static int h(Node n) {
return 2 * n.depth;
}
private static PriorityQueue<Node> frontier1 = new PriorityQueue<>(Comparator.comparingInt(n -> f(n))); // no error
private static PriorityQueue<Node> frontier2 = new PriorityQueue<>(Comparator.comparingInt(Trial::f)); // no error
private static PriorityQueue<Node> frontier3 = new PriorityQueue<>(Comparator.comparingInt(n -> f(n)).thenComparingInt(n -> h(n))); // error
private static PriorityQueue<Node> frontier4 = new PriorityQueue<>(Comparator.comparingInt(Trial::f).thenComparingInt(n -> h(n))); // no error
private static PriorityQueue<Node> frontier5 = new PriorityQueue<>(Comparator.comparingInt(Trial::f).thenComparingInt(Trial::h)); // no error
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected no syntax error for frontier3 declaration
ACTUAL -
Error messages:
'- The method f(Node) in the type Trial is not applicable for the arguments (Object)'
'incompatible types: java.lang.Object cannot be converted to Node'
System.getProperty("java.version") = 23.0.1
Eclipse Adoptium jdk-23.0.1.11-hotspot
A DESCRIPTION OF THE PROBLEM :
Getting syntax error for a perfectly valid declaration of Comparator. The syntax error is obtained while entering code in Eclipse 2024-09 or in VSCode jupyter notebook with Java kernel. The declaration involves Comparator.comparingInt(n -> f(n)).thenComparingInt(n -> h(n))
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
class Node {
public int depth;
public Node(int depth) {
this.depth = depth;
}
}
class Trial {
public static int f(Node n) {
return n.depth;
}
public static int h(Node n) {
return 2 * n.depth;
}
private static PriorityQueue<Node> frontier1 = new PriorityQueue<>(Comparator.comparingInt(n -> f(n))); // no error
private static PriorityQueue<Node> frontier2 = new PriorityQueue<>(Comparator.comparingInt(Trial::f)); // no error
private static PriorityQueue<Node> frontier3 = new PriorityQueue<>(Comparator.comparingInt(n -> f(n)).thenComparingInt(n -> h(n))); // error
private static PriorityQueue<Node> frontier4 = new PriorityQueue<>(Comparator.comparingInt(Trial::f).thenComparingInt(n -> h(n))); // no error
private static PriorityQueue<Node> frontier5 = new PriorityQueue<>(Comparator.comparingInt(Trial::f).thenComparingInt(Trial::h)); // no error
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected no syntax error for frontier3 declaration
ACTUAL -
Error messages:
'- The method f(Node) in the type Trial is not applicable for the arguments (Object)'
'incompatible types: java.lang.Object cannot be converted to Node'