LINQ for Java tool [closed]

LINQ for Java would be lovely, but the problem is the language integration.

Java doesn’t have anything as concise as lambda expressions, and they’re one of the bedrocks of LINQ. I suppose they could layer the query expression support on top of normal Java without lambda expressions, by making the expansion create anonymous inner classes – but it would be pretty hideous. You’d also need expression trees if you wanted to do anything like LINQ to SQL.

Checked exceptions might get in the way, but we’d have to see. The equivalent of IQueryable would need to have some sort of general checked exception – or possibly it could be generic in both the element type and the exception type…

Anyway, this is all pie-in-the-sky – given the troubles the Java community is having with closures, I think it would be folly to expect anything like LINQ in Java itself earlier than about 2012. Of course, that’s not to say it wouldn’t be possible in a “Java-like” language. Groovy has certain useful aspects already, for instance.

For the library side, Hibernate already provides a “non-integrated” version of a lot of the features of LINQ to SQL. For LINQ to Objects, you should look at the Google Java Collections API – it’s a lot of the same kind of thing (filtering, projecting etc). Without lambdas it’s a lot fiddlier to use, of course – but it’s still really, really handy. (I use the Google Collections code all the time at work, and I’d hate to go back to the “vanilla” Java collections.)

Leave a Comment