Community
Participate
Working Groups
Here is a class that contains 3 methods. The first method is the original, the second is the Eclipse Lambdification of the original, and the third is a possible correct lambdification of the first method. package junk; import java.lang.reflect.Field; import java.security.AccessController; import java.security.PrivilegedExceptionAction; public class Junk7 { private static int readValue(final String name) throws Exception { final Class<?> clazz = Junk7.class; return AccessController.doPrivileged( new PrivilegedExceptionAction<Integer>() { public Integer run() throws Exception { Field field = clazz.getDeclaredField(name); field.setAccessible(true); return field.getInt(clazz); } }); } //BAD - result of bad lamdification by Eclipse (does not compile) private static int readValueBAD(final String name) throws Exception { final Class<?> clazz = Junk7.class; return AccessController.doPrivileged( () -> { Field field = clazz.getDeclaredField(name); field.setAccessible(true); return field.getInt(clazz); }); } //GOOD - this is an example of possible good lambdification private static int readValueGOOD(final String name) throws Exception { final Class<?> clazz = Junk7.class; return AccessController.doPrivileged( (PrivilegedExceptionAction<Integer>) () -> { Field field = clazz.getDeclaredField(name); field.setAccessible(true); return field.getInt(clazz); }); } }
To spell out the problem: return AccessController.doPrivileged( ^^^^^^^^^^^^ The method doPrivileged(PrivilegedAction<Integer>) is ambiguous for the type AccessController Moving to JDT/UI
See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=403749#c22 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=423439. The present one is likely a duplicate of https://bugs.eclipse.org/bugs/show_bug.cgi?id=423439.
*** This bug has been marked as a duplicate of bug 423439 ***