classafBeanUtils::ReflectUtils

sys::Obj
  afBeanUtils::ReflectUtils

@Js

Static methods for finding fields, methods and ctors that match given parameter types.

argTypesFitFunc

Source

const static Bool argTypesFitFunc(Type?[] argTypes, Func func)

Returns true if the given parameter types fit the given func.

argTypesFitMethod

Source

const static Bool argTypesFitMethod(Type?[] argTypes, Method method)

Returns true if the given parameter types fit the method signature.

findCtor

Source

const static Method? findCtor(Type type, Str ctorName, Type?[]? params := null)

Finds a named ctor with the given parameter types.

Returns null if not found.

findCtors

Source

const static Method[] findCtors(Type type, Type?[]? params := null)

Find ctors with the given parameter types.

findField

Source

const static Field? findField(Type type, Str fieldName, Type? fieldType := null, Bool? isStatic := null)

Finds a named field.

Returns null if not found.

findFields

Source

const static Field[] findFields(Type type, Type fieldType, Bool? isStatic := null)

Find fields.

findMethod

Source

const 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 null if not found.

findMethods

Source

const static Method[] findMethods(Type type, Type?[]? params := null, Bool? isStatic := null, Type? returnType := null)

Find methods with the given parameter types.

fits

Source

const 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. Returns true if typeA fits into typeB.

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 into Int[].

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 create Obj?[] and Obj: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.