public final class IntersectionCastSupport
extends Object
Runtime support for intersection-type cast and as coercion
(GROOVY-11998). Compiler-generated bytecode for (A & B) value and
value as (A & B) routes through these helpers when the target is
an intersection type and the source is not a native lambda or method
reference (those cases are handled at compile time via
LambdaMetafactory.altMetafactory markers).
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static Object |
asType(Object source, Class<?>[] components)Coercion: produce an object that satisfies every component. |
|
public static Object |
castTo(Object source, Class<?>[] components)Strict cast: every component must already be assignment-compatible with the source's runtime class. |
Coercion: produce an object that satisfies every component. For Closure and Map sources, a multi-interface proxy is built via ProxyGenerator. For other sources, falls back to castTo so the behaviour is at least as strict as a cast.
Strict cast: every component must already be assignment-compatible with the source's runtime class. Throws GroovyCastException otherwise.