Created
December 4, 2013 23:18
-
-
Save anonymous/7797380 to your computer and use it in GitHub Desktop.
preprocessing java ftw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gcc -E -P Test.java.c > Test.java | |
$ javac Test.java | |
$ java Test | |
Bar ist 3 Jahre alt | |
Foo ist 5 Jahre alt | |
Qux ist 6 Jahre alt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SORT(list,T,code) java.util.Arrays.sort(list, new java.util.Comparator<T>() { public int compare(T a, T b) { code } }) | |
class Person { | |
String name; | |
int age; | |
Person(String name, int age) { this.name=name; this.age=age; } | |
} | |
class Test { | |
public static void main(String[] args) { | |
Person[] personen = new Person[]{new Person("Foo", 5), new Person("Bar", 3), new Person("Qux", 6)}; | |
// sort by age | |
SORT(personen,Person, { | |
if (a.age < b.age) return -1; | |
if (a.age > b.age) return 1; | |
return 0; | |
}); | |
for (Person p: personen) System.out.println(p.name+" ist "+p.age+" Jahre alt"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment