classafBeanUtils::ReflectUtils
sys::Obj afBeanUtils::ReflectUtils
@Js
Static methods for finding fields, methods and ctors that match given parameter types.
- _findCtor
- _findMethod
static Method? _findMethod(Slot? method, Type[] params, Bool? isStatic, Type? returnType)- argTypesFitFunc
static Bool argTypesFitFunc(Type?[] argTypes, Func func)Returns
trueif the given parameter types fit the given func.- argTypesFitMethod
static Bool argTypesFitMethod(Type?[] argTypes, Method method)Returns
trueif the given parameter types fit the method signature.- findCtor
static Method? findCtor(Type type, Str ctorName, Type[]? params := null)Finds a named ctor with the given parameter types.
Returns
nullif not found.- findCtors
static Method[] findCtors(Type type, Type[]? params := null)Find ctors with the given parameter types.
- findField
static Field? findField(Type type, Str fieldName, Type? fieldType := null, Bool? isStatic := null)Finds a named field.
Returns
nullif not found.- findFields
static Field[] findFields(Type type, Type fieldType, Bool? isStatic := null)Find fields.
- findMethod
static Method? findMethod(Type type, Str methodName, Type[]? params := null, Bool? isStatic := null, Type? returnType := null)Finds a named method with the given parameter types.
Returns
nullif not found.- findMethods
static Method[] findMethods(Type type, Type[]? params := null, Bool? isStatic := null, Type? returnType := null)Find methods with the given parameter types.
- fits
static Bool fits(Type? typeA, Type? typeB)A replacement for
Type.fits()that takes into account type inference for Lists and Maps, and fixes Famtom bugs. ReturnstrueiftypeAfits intotypeB.Standard usage:
Str#.fits(Obj#) // --> true ReflectUtils.fits(Str#, Obj#) // --> true
List (and Map) type checking:
Int[]#.fits(Obj[]#) // --> true ReflectUtils.fits(Int[]#, Obj[]#) // --> true
List (and Map) type inference. Items in
Obj[]may fit intoInt[].Obj[]#.fits(Int[]#) // --> false ReflectUtils.fits(Obj[]#, Int[]#) // --> true
This is particularly important when calling methods, for many Lists and Maps are defined by the shortcuts
[,]and[:]which createObj?[]andObj:Obj?respectively.But List (and Map) types than can never fit still return
false:Str[]#.fits(Int[]#) // --> false ReflectUtils.fits(Str[]#, Int[]#) // --> false
Fantom (nullable) bug fix for Lists (and Maps):
Int[]#.fits(Int[]?#) // --> false ReflectUtils.fits(Int[]#, Int[]?#) // --> true
See List Types and Nullability for bug details.