(final ELContext ctx, final LambdaExpression lambdaExpression,
final Class<T> type)
| 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 | /** |
no test coverage detected