abstract rtconst class std::Type


Type defines the contract of an Obj by the slots its supports. Types model the inheritance relationships and provide a mapping for all the slots both inherited and declared.


abstract Type? base()

The direct super class of this type (null for Obj). Return sys::Obj for all mixin types.


Obj#.base        =>  null
Int#.base        =>  sys::Num
OutStream#.base  =>  sys::Obj

virtual Str? doc()

Return the raw fandoc for this type or null if not available.


abstract Facet? facet(Type type, Bool checked := true)

Get a facet by its type. If not found on this type then return null or throw UnknownFacetErr based on check flag. See Facets Doc for details.


abstract List<Facet> facets()

Get the list of facets defined on this type or return an empty list if no facets are defined. If looking up a facet by type, then use the facet method which will provide better performance. See Facets Doc for details.


Field? field(Str name, Bool checked := true)

Convenience for (Field)slot(name, checked)


abstract List<Field> fields()

List of the all defined fields (including inherited fields).


static Type? find(Str qname, Bool checked := true)

Find a Type by it's qualified name "pod::Type". If the type doesn't exist and checked is false then return null, otherwise throw UnknownTypeErr.


virtual Bool fits(Type t)

Does this type implement the specified type. If true, then this type is assignable to the specified type (although the converse is not necessarily true). This method provides the same semantics as the is operator, but between two types rather than an instance and a type. All types (including mixin types) fit sys::Obj.


Float#.fits(Float#) =>  true
Float#.fits(Num#)   =>  true
Float#.fits(Obj#)   =>  true
Float#.fits(Str#)   =>  false
Obj#.fits(Float#)   =>  false

protected abstract Int flags()


Bool hasFacet(Type type)

Return if this type has the specified facet defined.


abstract List<Type> inheritance()

Return a recursive flattened list of all the types this type inherits from. The result list always includes this type itself. The result of this method represents the complete list of types implemented by this type - instances of this type are assignable to any type in this list. All types (including mixins) will include sys::Obj in this list.


Obj#.inheritance  =>  [sys::Obj]
Int#.inheritance  =>  [sys::Int, sys::Num, sys::Obj]

Bool isAbstract()

Return if this Type is abstract and cannot be instantiated. This method will always return true if the type is a mixin.


Bool isClass()

Return if this Type is a class (as opposed to enum or mixin)


Bool isConst()

Return if this is a const class which means instances of this class are immutable.


Bool isEnum()

Return if this Type is an Enum type.


Bool isFacet()

Return if this Type is an Facet type.


Bool isFinal()

Return if this Type is marked final which means it may not be subclassed.


virtual Bool isGeneric()

A generic type contains slot signatures which may be parameterized - for example Map's key and value types are generic as K and V. Fantom supports three built-in generic types: List, Map, and Func. A parameterized type such as Str[] is not a generic type (all of its generic parameters have been filled in).


Str#.isGeneric   => false
List#.isGeneric  => true
Str[]#.isGeneric => false

virtual override Bool isImmutable()


Bool isInternal()

Return if this Type has internal protection scope.


Bool isMixin()

Return if this Type is a mixin type and cannot be instantiated.


virtual Bool isNullable()

Is this a nullable type. Nullable types can store the null value, but non-nullables are never null. Null types are indicated with a trailing "?".


virtual Bool isParameterized()

A parameterized type is a type which has parameterized a generic type and replaced all the generic parameter types with generic argument types. The type Str[] is a parameterized type of the generic type List (V is replaced with Str). A parameterized type always has a signature which is different from the qname.


Bool isPublic()

Return if this Type has public protection scope.


Bool isSynthetic()

Return if this Type was generated by the compiler.


virtual Bool isVal()

Is this a value type. Fantom supports three implicit value types: Bool, Int, and Float.


virtual Obj make(List<Obj>? args := null)

Create a new instance of this Type using the following rules:

  1. Call public constructor make with specified arguments
  2. If no public constructor called make or invalid number of of required arguments, then return value of defVal slot (must be static field or static method with zero params)
  3. If no public defVal field, then throw Err

Method? method(Str name, Bool checked := true)

Convenience for (Method)slot(name, checked)


abstract List<Method> methods()

List of the all defined methods (including inherited methods).


abstract List<Type> mixins()

Return the mixins directly implemented by this type.


Obj#.mixins        =>  [,]
Buf#.mixins        =>  [sys::InStream, sys::OutStream]
OutStream#.mixins  =>  [,]

abstract Str name()

Simple name of the type such as "Str". For parameterized types derived from List, Map, or Func, this method always returns "List", "Map", or "Func" respectively.


Str#.name         => "Str"
acme::Foo#.name   => "Foo"
acme::Foo[]#.name => "List"

static Type of(Obj obj)

Get the class Type of the given instance. Also see Obj.typeof which provides the same functionality.


abstract Pod? pod()

Parent pod which defines this type. For parameterized types derived from List, Map, or Func, this method always returns the sys pod.


Str#.pod         => sys
acme::Foo#.pod   => acme
acme::Foo[]#.pod => sys

new privateMake()

Private constructor.


abstract Str qname()

Qualified name formatted as "pod::name". For parameterized types derived from List, Map, or Func, this method always returns "sys::List", "sys::Map", or "sys::Func" respectively. If this a nullable type, the qname does not include the "?".


Str#.qname         => "sys::Str"
Str?#.qname        => "sys::Str"
acme::Foo#.qname   => "acme::Foo"
acme::Foo[]#.qname => "sys::List"

abstract Str signature()

Return the formal signature of this type. In the case of non-parameterized types the signature is the same as qname. For parameterized types derived from List, Map, or Func the signature uses the following special syntax:

List => V[]
Map  => [K:V]
Func => |A,B...->R|

If this is a nullable type, the signature ends with "?" such as "sys::Int?".


Str#.signature => "sys::Str"
Str?#.signature => "sys::Str?"
Int[]#.signature => "sys::Int[]"
Int:Str#.signature => "[sys::Int:sys::Str]"
Str:Buf[]#.signature => [sys::Str:sys::Buf[]]
|Float x->Bool|#.signature => "|sys::Float->sys::Bool|"
|Float x, Int y|#.signature => |sys::Float,sys::Int->sys::Void|

abstract Slot? slot(Str name, Bool checked := true)

Lookup a slot by name. If the slot doesn't exist and checked is false then return null, otherwise throw UnknownSlotErr. Slots are any field or method in this type's scope including those defined directly by this type and those inherited from super class or mixins.


abstract List<Slot> slots()

List of the all defined slots, both fields and methods (including inherited slots).


virtual override Obj toImmutable()


virtual Type toNonNullable()

Return this type as a non-nullable type. If this type is already non-nullable then return this.


abstract Type toNullable()

Return this type as a nullable type. If this type is already nullable then return this.


virtual override Str toStr()

Always return signature().


static extension Type typeof(Obj obj)

Get the Type instance which represents this object's class. Also see`Type.of` or Pod.of.