Package org.codehaus.groovy.runtime.typehandling

# Class ShortTypeHandling

java.lang.Object
org.codehaus.groovy.runtime.typehandling.ShortTypeHandling

public class ShortTypeHandling extends Object
High-performance type casting and conversion utilities.

Provides fast-path type conversions for common cases. These methods are designed to avoid dependency on the Groovy runtime and should be used directly only when the type constraints documented in each method are met.

For general-purpose type coercion, use `DefaultTypeTransformation` instead.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ShortTypeHandling()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Character`
  `castToChar(Object object)`
  Casts an object to a char value (Character wrapper).
  `static Class`
  `castToClass(Object object)`
  Casts an object to a Class object.
  `static Enum`
  `castToEnum(Object object, Class<? extends Enum> type)`
  Casts an object to an Enum value of the specified type.
  `static String`
  `castToString(Object object)`
  Casts an object to a String representation.

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

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

- ## Constructor Details

  - ### ShortTypeHandling

    public ShortTypeHandling()

- ## Method Details

  - ### castToClass

    public static Class castToClass(Object object)
    Casts an object to a Class object.

    Accepts Class objects directly, or a string representation of a class name which is loaded via `Class.forName`.

    Parameters:
      `object` - a Class object or string class name
    Returns:
      the Class object, or null if input is null
    Throws:
      `GroovyCastException` - if the object is not a Class or valid class name

  - ### castToString

    public static String castToString(Object object)
    Casts an object to a String representation.

    Arrays are converted using `Arrays.toString` format. Primitive arrays receive special handling to show element values. Other objects use their standard `toString()` method.

    Parameters:
      `object` - any object (may be null)
    Returns:
      string representation, or null if input is null

  - ### castToEnum

    public static Enum castToEnum(Object object, Class<? extends Enum> type)
    Casts an object to an Enum value of the specified type.

    Note: This method requires that the supplied enum is not fitting a Collection case for casting.

    Accepts Enum objects already of the correct type, or a String/GString representation of the enum constant name.

    Parameters:
      `object` - an enum value, or a string enum constant name
      `type` - the target enum class
    Returns:
      the Enum value, or null if input is null
    Throws:
      `GroovyCastException` - if the object cannot be converted to the enum type

  - ### castToChar

    public static Character castToChar(Object object)
    Casts an object to a char value (Character wrapper).

    Accepts Character objects, Numbers (converted via intValue), or Strings of length 1.

    Parameters:
      `object` - a Character, Number, or single-character String
    Returns:
      a Character with the coerced value, or null if input is null
    Throws:
      `GroovyCastException` - if the object cannot be converted to char