mixinafBeanUtils::BeanBuilder
afBeanUtils::BeanBuilder
@
Js
Static methods for creating Fantom objects. Don't make()
your beans, build()
them instead!
- build
static Obj? build(Type type, [Field:Obj?]? fieldVals := null, Obj?[]? ctorArgs := null)
Creates an instance of the given type, using the most appropriate ctor for the given args. Ctors with it-blocks are always favoured over ctors without.
- defVal
static Obj? defVal(Type type, Bool allowNull := true)
Returns a default value for the given type. Use as a replacement for Type.make().
Returned objects are not guaranteed to be immutable. Call
toImmutable()
on returned object if you needconst
Lists and Maps.The default type is determined by the following algorithm:
- If the type is nullable (and
allowNull == true
) returnnull
- If the type is a Map, an empty map is returned
- If the type is a List, an empty list is returned (with zero capacity)
- If one exists, a public no-args ctor is called to create the object
- If it exists, the value of the type's
defVal
slot is returned (must be a static field or method with zero params) ArgErr
is thrown
This method differs from Type.make() for the following reasons:
null
is returned if type is nullable.- Can create Lists and Maps
- The public no-args ctor can be called anything.
- If the type is nullable (and