Would a LINQ for java be a useful tool? I have been working on a tool that will allow a Java object to map to a row in a database.
- Would this be useful for Java programmers?
- What features would be useful?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.)