Class declaration.
Because some classes have type parameters, getting a model requires applying type arguments to the
class declaration with classApply()
in order to be able to instantiate that class. For example, here is how you would
obtain a class model that you can instantiate from a toplevel class declaration:
class Foo<T>(){ string => "Hello, our T is: ``typeLiteral<T>()``"; } void test(){ // We need to apply the Integer closed type to the Foo declaration in order to get the Foo<Integer> closed type Class<Foo<Integer>,[]> classModel = `class Foo`.classApply<Foo<Integer>,[]>(`Integer`); // This will print: Hello, our T is: ceylon.language::Integer print(classModel()); }
For member classes it is a bit longer, because member classes need to be applied not only their type arguments but also
the containing type, so you should use memberClassApply()
and start by giving the containing closed type:
class Outer(){ shared class Inner(){ string => "Hello"; } } void test(){ // apply the containing closed type `Outer` to the member class declaration `Outer.Inner` MemberClass<Outer,Outer.Inner,[]> memberClassModel = `class Outer.Inner`.memberClassApply<Outer,Outer.Inner,[]>(`Outer`); // We now have a MemberClass, which needs to be applied to a containing instance in order to become an // invokable class model: Class<Outer.Inner,[]> boundMemberClassModel = memberClassModel(Outer()); // This will print: Hello print(boundMemberClassModel()); }
no type hierarchy
no subtypes hierarchy
Attributes | |
abstract | Source Codeshared formal Boolean abstract True if the class has an abstract annotation. |
anonymous | Source Codeshared formal Boolean anonymous True if the class is an anonymous class, as is the case for the class of object value declarations. |
final | Source Codeshared formal Boolean final True if the class has a final annotation. |
objectValue | Source Codeshared formal ValueDeclaration? objectValue This anonymous class' object value declaration if this class is an anonymous class. |
Inherited Attributes |
Attributes inherited from: Object |
Attributes inherited from: ClassOrInterfaceDeclaration |
Attributes inherited from: Declaration |
Attributes inherited from: FunctionalDeclaration |
Attributes inherited from: GenericDeclaration |
Attributes inherited from: NestableDeclaration |
Attributes inherited from: TypedDeclaration |
Methods | |
classApply | Source Codeshared formal Class<Type,Arguments> classApply<Type = Anything, Arguments = Nothing>(Type<Anything>[] typeArguments) Applies the given closed type arguments to this toplevel class declaration in order to obtain a class model. See this code sample for an example on how to use this. Throws
|
instantiate | Source Codeshared default Anything instantiate(Type<Anything>[] typeArguments = [], Anything[] arguments) Creates a new instance of this toplevel class, by applying the specified type arguments and value arguments. Parameters:
Throws
|
memberClassApply | Source Codeshared formal MemberClass<Container,Type,Arguments> memberClassApply<Container = Nothing, Type = Anything, Arguments = Nothing>(Type<Container> containerType, Type<Anything>[] typeArguments) Applies the given closed container type and type arguments to this member class declaration in order to obtain a member class model. See this code sample for an example on how to use this. Throws
|
memberInstantiate | Source Codeshared default Anything memberInstantiate(Object container, Type<Anything>[] typeArguments = [], Anything[] arguments) Creates a new instance of this member class, by applying the specified type arguments and value arguments. Parameters:
Throws
|
Inherited Methods |
Methods inherited from: Object |
Methods inherited from: AnnotatedDeclaration |
Methods inherited from: ClassOrInterfaceDeclaration ClassOrInterfaceDeclaration.annotatedDeclaredMemberDeclarations() , ClassOrInterfaceDeclaration.annotatedMemberDeclarations() , ClassOrInterfaceDeclaration.apply() , ClassOrInterfaceDeclaration.declaredMemberDeclarations() , ClassOrInterfaceDeclaration.getDeclaredMemberDeclaration() , ClassOrInterfaceDeclaration.getMemberDeclaration() , ClassOrInterfaceDeclaration.memberApply() , ClassOrInterfaceDeclaration.memberDeclarations() |
Methods inherited from: FunctionalDeclaration |
Methods inherited from: GenericDeclaration |