This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary ======= If there is a type mismatch between a Predicate type and the lambda expression assigned to it, the error is correctly reported but the proposed hint is incorrect, and does nothing. Steps to reproduce ================== [1] Create a trivial Java application named TestPredicate as follows: package testpredicate; import java.util.function.Predicate; public class TestPredicate { public static void main(String[] args) { Predicate<Integer> gt30 = i -> i > 30; Predicate<Integer> gt40 = (i) -> i > 40; Predicate<Integer> gt50 = (Integer i) -> i > 50; Predicate<Integer> gt60 = (Short i) -> i > 60; } } [2] Compile the code. The only error is on the final line of code, where the type of the Predicate (Integer) does not match the parameter type of the lambda expression (Short). [3] The error is correctly reported by the compiler: error: "incompatible types: incompatible parameter types in lambda expression". [4] Press alt-enter on the failing line. The hint proposed is "Change type of gt60 to Predicate<Integer>". This is exactly what the code already shows, and accepting the hint does nothing. [5] It would be more useful if two hints were offered, to make the generic type of the Predicate match the type of the lambda argument, or vice versa. In this example those hints might be: Hint 1: "Change type of gt60 to Predicate<Short>" Hint 2: "Change type of lambda argument to Integer" Environment =========== Product Version: NetBeans IDE 8.0.1 (Build 201408251540) Updates: NetBeans IDE is updated to version NetBeans 8.0.1 Patch 1.1 Java: 1.8.0_25; Java HotSpot(TM) 64-Bit Server VM 25.25-b02 Runtime: Java(TM) SE Runtime Environment 1.8.0_25-b18 System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb) User directory: C:\Users\JohnDoe\AppData\Roaming\NetBeans\8.0.1 Cache directory: C:\Users\JohnDoe\AppData\Local\NetBeans\Cache\8.0.1
I cowardly admit that I am unable to compute (or have the javac to compute for me) the correct type of either the lambda's parameters or the compatible outcome type. So I'll disable the fix in this situation until a way how to get the correct type is found. Lahvaci - could you help, please ? fix removed in jet-main#558d88ea1485; turning to enhancement
Integrated into 'main-silver', will be available in build *201505120001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/558d88ea1485 User: Svata Dedic <sdedic@netbeans.org> Log: #248476: cowardly disabled hint when lambda is assigned to a variable