Skip to content

Instantly share code, notes, and snippets.

@daveshah
Created March 14, 2012 02:20
Show Gist options
  • Save daveshah/2033487 to your computer and use it in GitHub Desktop.
Save daveshah/2033487 to your computer and use it in GitHub Desktop.
Example of Extension Methods on Strings in Xtend
import junit.framework.Assert
import org.junit.Test
class ExtensionMethodsTest {
@Test
def shouldBeNull() {
var String myTestString = null;
Assert::assertTrue(myTestString.isEmptyOrNull());
}
@Test
def shouldBeEmpty() {
var String myTestString = "";
Assert::assertTrue(myTestString.isEmptyOrNull());
}
def isEmptyOrNull(String s) {
s == null || s.isEmpty()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment