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.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static Character |
castToChar(Object object)Casts an object to a char value (Character wrapper). |
|
public static Class |
castToClass(Object object)Casts an object to a Class object. |
|
public static Enum |
castToEnum(Object object, Class<? extends Enum> type)Casts an object to an Enum value of the specified type. |
|
public static String |
castToString(Object object)Casts an object to a String representation. |
Casts an object to a char value (Character wrapper).
Accepts Character objects, Numbers (converted via intValue), or Strings of length 1.
object - a Character, Number, or single-character StringCasts an object to a Class object.
Accepts Class objects directly, or a string representation of a class name
which is loaded via Class.forName.
object - a Class object or string class nameCasts 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.
object - an enum value, or a string enum constant nametype - the target enum classCasts 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.
object - any object (may be null)