2010-03-14

But Java /can/ do that!

I recently attended a talk at FOSDEM by Miguel de Icaza, a fellow enemy of "Free" software.

He, like most .NET users, is desperately seeking features to differentiate his second-rate platform from the wonderfulnessness of Java.

He showed .NET expressions, a wonderful feature whereby the actual nature of a predicate can be retrieved at runtime and optimal, say, SQL can be built to match it.

He, however, claimed that Java lacks this feature. This is not the case.

ExpressionTest shows various uses of this in Java; basically:

Expression.toSQL(new Predicate<FooDTO>() { @Override public boolean matches(FooDTO t) { t.a == 7; } });

will return:

(a = 7)

Obviously this remains slightly more verbose while the Java lambda proposals are finalised, but the feature is hardly missing!

Similarily,

return (t.a == 7 || t.a == 8 || t.a == 9) && "pony".equals(t.b);

becomes:

(a = 7 AND b = 'pony') OR 
(a = 8 AND b = 'pony') OR
(a = 9 AND b = 'pony')

And, etc.

The implementation, if the devil compels you to look.


Commenting is disabled for this post.

Read more of Faux' blog