Package org.codehaus.groovy.runtime

# Class IntersectionCastSupport

java.lang.Object
org.codehaus.groovy.runtime.IntersectionCastSupport

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).

Since:
  6.0.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Object`
  `asType(Object source, Class<?>[] components)`
  Coercion: produce an object that satisfies every component.
  `static Object`
  `castTo(Object source, Class<?>[] components)`
  Strict cast: every component must already be assignment-compatible with the source's runtime class.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### castTo

    public static Object castTo(Object source, Class<?>[] components)
    Strict cast: every component must already be assignment-compatible with the source's runtime class. Throws `GroovyCastException` otherwise.

  - ### asType

    public static Object asType(Object source, Class<?>[] components)
    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(java.lang.Object, java.lang.Class<?>[])` so the behaviour is at least as strict as a cast.