MCPcopy Index your code
hub / github.com/apache/tomcat / coerceToFunctionalInterface

Method coerceToFunctionalInterface

java/org/apache/el/lang/ELSupport.java:662–682  ·  view source on GitHub ↗
(final ELContext ctx, final LambdaExpression lambdaExpression,
            final Class<T> type)

Source from the content-addressed store, hash-verified

660
661
662 private static <T> T coerceToFunctionalInterface(final ELContext ctx, final LambdaExpression lambdaExpression,
663 final Class<T> type) {
664 Supplier<T> proxy = () -> {
665 // Create a dynamic proxy for the functional interface
666 @SuppressWarnings("unchecked")
667 T result = (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type },
668 (Object obj, Method method, Object[] args) -> {
669 // Functional interfaces have a single, abstract method
670 if (!Modifier.isAbstract(method.getModifiers())) {
671 throw new ELException(MessageFactory.get("elSupport.coerce.nonAbstract", type, method));
672 }
673 if (ctx == null) {
674 return lambdaExpression.invoke(args);
675 } else {
676 return lambdaExpression.invoke(ctx, args);
677 }
678 });
679 return result;
680 };
681 return proxy.get();
682 }
683
684
685 /**

Callers 1

coerceToTypeMethod · 0.95

Calls 5

getMethod · 0.95
isAbstractMethod · 0.80
getClassLoaderMethod · 0.65
invokeMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected