public class CastUtil extends Object
Note: This class is not a part of the public API and is subject to change. Do not use it in your own code
Modifier and Type | Method and Description |
---|---|
static Injectable |
toType(Object value,
Type type)
Attempts to cast the given value to the provided
Type . |
static Injectable |
toType(Object value,
Type type,
BiFunction<Object,Type,Object> converter)
Attempts to cast the given value to the provided
Type . |
@Nonnull public static Injectable toType(Object value, Type type)
Type
. Designed for use with Sling injectorsvalue
- An arbitrary valuetype
- A Type
reference. Usually reflects the type of Java class memberInjectable
instance containing the transformed value; can contain null
if type casting
was not possible@Nonnull public static Injectable toType(Object value, Type type, BiFunction<Object,Type,Object> converter)
Type
. Designed for use with Sling injectorsvalue
- An arbitrary valuetype
- A Type
reference. Usually reflects the type of Java class memberconverter
- A function that we use to convert a single entry of the provided value into the given type.
Considering the given value is an array or collection, the converter
must process every
separate array's (collection's) element. If the given value is a singleton object or primitive,
the converter
processes it as isInjectable
instance containing the transformed value; can contain null
if type casting
was not possibleCopyright © 2024 Exadel, Inc.. All rights reserved.