classafBeanUtils::ReflectUtils
sys::Obj afBeanUtils::ReflectUtils
@Js
Static methods for finding fields, methods and ctors that match given parameter types.
- 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, Bool matchArity := false)Returns
trueif the given parameter types fit the method signature.This has the same leniency as if you were calling the method function - so will return
trueeven if there are moreargTypesthan method parameters.Set
matchAritytotruefor a stricter match, more appropriate for methods.- 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, Bool matchArity := false)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, Bool matchArity := false)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 fits(Str#, Obj#) // --> true
List (and Map) type checking:
Int[]#.fits(Obj[]#) // --> true fits(Int[]#, Obj[]#) // --> true
List (and Map) type inference. Items in
Obj[]may fit intoInt[].Obj[]#.fits(Int[]#) // --> false 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 fits(Str[]#, Int[]#) // --> false
Fantom (nullable) bug fix for Lists (and Maps):
Int[]#.fits(Int[]?#) // --> false fits(Int[]#, Int[]?#) // --> true
See List Types and Nullability for bug details.