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

查看:24
本文介绍了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 代码,我不想回到普通"Java 集合.)

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天全站免登陆