--- layout: post title: Xtend 2.6.0 Release Notes date: 2014-05-21 09:30:28 categories: releasenotes ---
Version 2.6 got many bug fixes and performance improvements (full bugzilla list). The new features are the following.
Xtend supports using lambdas to implement anonymous classes with just one abstract method since its inception. For interfaces and abstract classes with more than one method you can now also use the an anonymous class using the following syntax:
val tabListener = new ActionBar.TabListener() {
override onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// show the given tab
}
override onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
// hide the given tab
}
override onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
// probably ignore this event
}
};
Xtend now supports static nested classes.
class A {
static class NestedClass {
}
}
In addition to overloading operators by adhering to the name mappings, listed in the documentation, one can now use the actual operator in the declaration as well.
class Money {
def + (Money other) { ... }
def - (Money other) { ... }
def * (BigDecimal times) { ... }
...
}
The synchronized expression works basically like Java's synchronized statement.
synchronized(lock) {
// do stuff
}
But of course it is an expression, as everything in Xtend/Xbase. So you can write the following as well:
someMethodCall(synchronized(lock) { ... })
It is now possible to import features in a fully qualified way. This works for regular static imports as well as for extension imports.
// static import import static java.util.Collections.singleton // extension import import static extension java.util.Collections.min import static extension java.util.Collections.max
The switch expression now supports a kind of fall through. Here's an example
switch myOperator {
case '+',
case '-' : handlePlusMinus()
case '*',
case '/' : handleDivMultiply()
default : throw new IllegalStateException
}
Xtend now supports compound assignment operators.
var i = 0 i += 42
Compound operators work on overloaded operators as well. That is you don't need to declare '+=' if you have '+' defined. Example:
var distance = 15.km distance += 5.km
Postfix operators for incrementing and decrementing numbers have been added.
var i = 0
while (condition()) {
i++
}
The traditional for-loop from Java is now available in Xtend, too.
for (var i = 0; i < 99; i++) {
println(''+i+' bottles of beer on the wall.')
}
Instead of writing
@SurpressWarnings(#["unused", "unchecked"])
you can write
@SurpressWarnings("unused", "unchecked")
When initializing a final field within a synthetic constructor, the control flow analysis couldn't detect it was in fact initialized and would raise an error. Another typical solution was a warning when a private field was only accessed through methods added by an active annotation (e.g. a setter or getter). You can now mark a field as read resp. initialized.
2.6 adds the following optional compiler checks (inactive by default):
In addition to the "Go to declaration"-action, you can now navigate to existing implementations of a method. It works just like in JDT
In a debug session, when hovering over a local variable or a visible field, the popo up shows the inspection tree of the hovered value.
The declaration hover now includes the annotations.
A gradle plug-in for easy integration of the Xtend compiler in any gradle based Java projects is now available.
The gradle plug-in even also works with the new Android buildsystem developed by Google.
The gradle plug-in is hosted at github.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.xtend:xtend-gradle-plugin:0.0.8'
}
}
apply plugin: 'xtend'
repositories {
mavenCentral()
}
dependencies {
//or testCompile if you only want to use Xtend for some tests
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.6.0'
}
For large Android projects there is a need to have as little code packaged as possible. Usually this is achieved by proguarding cour code and the dependencies during the build. For people who find that tedious and want to work with a reduced lib from the get go, we offer a treeshaken version of the library, which is only 300k small.
The library can be downloaded from maven central.