doPrivileged with lambda

Weijun Wang weijun.wang at oracle.com
Fri May 10 08:56:06 UTC 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 
frustration.

-Max



More information about the security-dev mailing list