Java Expression Trees [closed]

百般思念 提交于 2019-12-05 09:12:30

问题


Is there an equivalent of .net's Expression Trees that underly LINQ for the JVM? I would like to implement some LINQ like code structures in Scala and I am wondering if I have to roll my own expression tree library also.

Update: I am not interested in a linq equivalent itself. .net has a large set of expression tree tools that make it easy to dynamically compile code at runtime can have it be callable from your code. The project I want to undertake has no relation to databases. Expression tree's provide an easy way to describe code that operates on data.

If there is no library my other option I think is to create one that emits byte code.


回答1:


Since 2.10, Scala has macros, which give you access to abstract syntax trees of their arguments at compile-time: http://scalamacros.org/. Here are some examples of their usage including a sketch of LINQ: http://scalamacros.org/paperstalks/2013-12-02-WhatAreMacrosGoodFor.pdf.




回答2:


The closest thing I am aware of is Julian Hyde's linq4j and Optiq libraries. They have an expression tree model, support a LINQ-like model of programming (subject to Java syntax) against many types of data sources.



来源:https://stackoverflow.com/questions/1479547/java-expression-trees

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!