doPrivileged with lambda

Weijun Wang at
Fri May 10 01:56:06 PDT 2013

So we have been writing

     x = AccessController.doPrivileged(
             new PrivilegedAction<Object>() {
                 public Object run() {
                     return some();

Using jdk8 lambda, it seems we can write

     x = AccessController.doPrivileged(() -> some());

But it does not compile, because () -> some() matches both 
PrivilegedAction and PrivilegedExceptionAction. So it has to be

     x = AccessController.doPrivileged(
             (PrivilegedAction<Object>)(() -> some()));

which is cumbersome again.

I'm not requesting for any new API at the moment, just talking about my 


More information about the security-dev mailing list