Class Constructors in Xtend

I am trying Xtend . Is it possible to make constructors? It seems so simple, but I get an error when I try something like this:

class Scope extends Rect { public Scope(){ super() } } 
+5
source share
4 answers

Constructors are defined by overloading the new () method:

 class MyClass extends AnotherClass { new(String s) { super(s) } new() { this("default") } } 

look here

+12
source

The next release of Xtend is scheduled for mid-December. He will support the declaration of designers.

See http://www.eclipse.org/Xtext/xtend/#whatsnext

+2
source

Constructors are not yet supported in Xtend. The def Scope () clause is more a mistake than a working constructor. You can follow this ticket .

+1
source

Xtend 2.0 does not have constructor support. I think this is a show stopper.

"class Foo {def Foo () {/ stuff /}} declares a Foo method for Foo instances with the returned return type, and not the constructor, when the generated Java code is displayed.

This means that there is no way to extend Java classes that do not have default constructors. XTend does not complain; it happily generates Java that does not compile.

In addition, XTend does not support immutable (final) instance variables, of course.

+1
source

Source: https://habr.com/ru/post/1379952/


All Articles