klyn.Type.createInstance
method
public createInstance(args... as Object) as Object throws Exception
Description

Creates an instance of this type through reflection.

Constructor overloads are selected from both the supplied argument count and their runtime types. Exact types take precedence over compatible base types and implicit widening numeric conversions. Constructors with default trailing parameters can be called with omitted arguments. A null argument excludes candidates whose corresponding parameter is declared notnull. Primitive and other ValueType parameters never accept null either.

Parameters
ParameterDescription
argsConstructor arguments.
Returns

New instance.

Throws
  • TypeError if this type is abstract or an interface, or if no accessible constructor matches the supplied arguments.
  • Exception if no constructor matches or if construction fails.
Example
user = User.type.createInstance("Alice") as User
assert (String.type.createInstance(null) as String) == "null"