I know that its possible to redefine operands with Xtend. My question is, can I redefine an operand using Xtend code and then import this source code into Java project to use it?

For example I would redefine the operand + with Xtend, than I import this source into my Java project and use the redefined operand. Is it possible?

有帮助吗?

解决方案 2

Create or copy an Xtend file into a Java project, then just open it, this will install the Xtend builder on the project. Now, you will have a problem marker on the first line of code, quick fix it with Ctrl+1, this will add the necessary Xtend libs to the classpath. That's all.

Source: the Getting Started section of Xtend's installation instructions.

Note: as @rzymek says, you will be able to use the overriden operator only in Xtend, Java will only see the method operator_plus.

其他提示

You can't redefine operators in Java. You can in Xtend.
Xtend compiler will generate e1.operator_plus(e2) Java code, when you're calling an overriden + operator.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top