LINQ for Java工具 [英] LINQ for Java tool

查看:127
本文介绍了LINQ for Java工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LINQ for java会成为一个有用的工具吗?我一直在研究一种允许Java对象映射到数据库中的行的工具。

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.


  1. 这对Java
    程序员有用吗?


  2. 有什么功能?


推荐答案

LINQ for Java会很可爱,但问题在于语言集成。

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

Java没有像lambda表达式那样简洁的东西,它们是LINQ的基石之一。我认为他们可以在没有lambda表达式的普通Java之上对查询表达式支持进行分层,通过使扩展创建匿名内部类 - 但它会非常可怕。如果你想做LINQ to SQL这样的事情,你还需要表达式树。

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.

检查异常可能会阻碍,但我们我必须看到。 IQueryable的等价物需要具有某种一般的检查异常 - 或者它可能在元素类型和异常类型中都是通用的......

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...

无论如何,这是天上掉馅饼 - 考虑到Java社区关闭的麻烦,我认为在2012年之前预期像Java中的LINQ这样的东西是愚蠢的。当然,这并不是说它不会用类似Java的语言是可能的。例如,Groovy已经有了一些有用的方面。

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.

对于库方面,Hibernate已经提供了LINQ to SQL的许多功能的非集成版本。对于LINQ to Objects,您应该查看 Google Java Collections API - 这是很多相同类型的事物(过滤,投射等)。当然,如果没有lambdas,它的使用时间会非常繁琐 - 但它仍然非常非常方便。 (我在工作中一直使用Google Collections代码,我不想回到vanillaJava集合。)

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.)

这篇关于LINQ for Java工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆