I am able to reference a named constructor by using `new MyClass.named` or the unnamed one with `new MyClass`. I then assumed that I could do the same for classes that use initializer parameters instead.
This will not compile however, the error message "Referenced declaration is not a constructor: NoCtor is a class" is displayed instead:
class NoCtor(String name) {}
class WithCtor {
shared new(String name) {}
}
// This works as expected
value ctor = `new WithCtor`;
// TODO: This does not compile
value ctor2 = `new NoCtor`;
// NOTE: You can access the CallableConstructor using reflection
value ctorR = `class WithCtor`.constructorDeclarations().first;
value ctorR2 = `class NoCtor`.constructorDeclarations().first;
This applies to both Eclipse (Ceylon 1.3.3) and the Web IDE (see here).
Right, this behavior is what is defined by the language specification. However, I agree that it does violate the expectation that one can change between default constructors and initializers without breaking code.
I am able to reference a named constructor by using
`new MyClass.named`
or the unnamed one with`new MyClass`
. I then assumed that I could do the same for classes that use initializer parameters instead.This will not compile however, the error message "Referenced declaration is not a constructor: NoCtor is a class" is displayed instead:
This applies to both Eclipse (Ceylon 1.3.3) and the Web IDE (see here).