New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced ACL.lambda convenience method #3260

Merged
merged 3 commits into from Feb 2, 2018

Conversation

3 participants
@jglick
Member

jglick commented Jan 23, 2018

Self-contained, but filing for discussion to see whether reviewers consider this type of addition desirable—if so, it could be extended to other similar cases in core and plugins.

Java 8 lambdas can automatically be cast to single-abstract-method (SAM) interfaces, but for reasons discussed in the expert group, not to abstract classes. This makes it awkward for -source 8 code to implement otherwise simple interfaces such as ACL, which are logically just a single function with a type signature and documentation—i.e., what could have been a @FunctionalInterface with default methods had that been an option when the API was written. By introducing an adapter method taking a SAM (such as from java.util.function.*), we can make it possible to write code which is almost as concise as an implicit cast to a SAM.

Proposed changelog entry:

  • Added convenience API method ACL.lambda.

@jenkinsci/code-reviewers @reviewbybees

@jglick jglick added the needs-review label Jan 23, 2018

@daniel-beck

This comment has been minimized.

Member

daniel-beck commented Jan 24, 2018

Looks reasonable, although I wonder about the naming.

@oleg-nenashev

Documentation should be extended, but LGTM in general

@@ -95,6 +96,15 @@ public final boolean hasPermission(@Nonnull Permission p) {
*/
public abstract boolean hasPermission(@Nonnull Authentication a, @Nonnull Permission permission);
public static ACL lambda(final BiFunction<Authentication, Permission, Boolean> impl) {

This comment has been minimized.

@oleg-nenashev

oleg-nenashev Feb 1, 2018

Member

Some javadoc would be useful

jglick added some commits Feb 1, 2018

@oleg-nenashev

🐝

@oleg-nenashev

This comment has been minimized.

Member

oleg-nenashev commented Feb 2, 2018

@oleg-nenashev oleg-nenashev merged commit ac05680 into jenkinsci:master Feb 2, 2018

1 check passed

continuous-integration/jenkins/pr-head This commit looks good
Details

@jglick jglick deleted the jglick:ACL.lambda branch Feb 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment