mixinafBeanUtils::BeanBuilder

afBeanUtils::BeanBuilder

@Js

Static methods for creating Fantom objects. Don't make() your beans, build() them instead!

build

Source

const 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

Source

const 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 need const Lists and Maps.

The default type is determined by the following algorithm:

  1. If the type is nullable (and allowNull == true) return null
  2. If the type is a Map, an empty map is returned
  3. If the type is a List, an empty list is returned (with zero capacity)
  4. If one exists, a public no-args ctor is called to create the object
  5. If it exists, the value of the type's defVal slot is returned (must be a static field or method with zero params)
  6. 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.