Coerce the supplied object to the requested type. @param The type to which the object should be coerced @param obj The object to be coerced @param type The type to which the object should be coerced @return An instance of the requested type. @throws ELException If the conversion fails @sin
(Object obj, Class<T> type)
| 354 | * @since EL 3.0 |
| 355 | */ |
| 356 | public <T> T convertToType(Object obj, Class<T> type) { |
| 357 | |
| 358 | boolean originalResolved = isPropertyResolved(); |
| 359 | setPropertyResolved(false); |
| 360 | try { |
| 361 | ELResolver resolver = getELResolver(); |
| 362 | if (resolver != null) { |
| 363 | T result = resolver.convertToType(this, obj, type); |
| 364 | if (isPropertyResolved()) { |
| 365 | return result; |
| 366 | } |
| 367 | } |
| 368 | } finally { |
| 369 | setPropertyResolved(originalResolved); |
| 370 | } |
| 371 | |
| 372 | if (obj instanceof LambdaExpression && isFunctionalInterface(type)) { |
| 373 | ((LambdaExpression) obj).setELContext(this); |
| 374 | } |
| 375 | |
| 376 | return ELManager.getExpressionFactory().coerceToType(obj, type); |
| 377 | } |
| 378 | |
| 379 | |
| 380 | /* |
no test coverage detected