Translation Using asSam() and LINQ for Java

Alessio Stalla alessiostalla at gmail.com
Sun May 30 07:18:35 PDT 2010


On Sat, May 29, 2010 at 9:16 AM, Ming-Yee Iu <mingyeeiu+lambda at gmail.com> wrote:
>> Please forgive my ignorance, but isn't LINQ a purely compile-time
>> transformation?
>>
>> Alessio
>
> Yes, LINQ, as implemented by Microsoft, is a purely compile-time
> transformation. Although Oracle now directs Java, it will probably
> take a long, long time for compiler support for database queries to be
> added to Java, if ever.
>
> So the most practical way to add support LINQ-style queries to Java
> within the next 5 years would be through classloader tricks or other
> bytecode rewriting techniques. Unfortunately, using asSam() for lambda
> expressions causes problems for this bytecode rewriting.

I think that implementing LINQ with bytecode analysis is the wrong
approach, for two reasons:

- One the most important features of LINQ is the integration in the
host language's syntax. Without that, you don't have a query DSL
anymore, just a clever API. To have that feature, compile-time support
is needed, and once you modify the compiler, there's no reason to do
bytecode analysis anymore.

- If closures will be added to the Java language specification, only
their syntax and semantics will be specified - not their
implementation. So basing bytecode analysis on the fact that the Sun
JVM will implement closures a certain way will likely make "LINQ" work
only on JVMs that implement closures the same way as Sun. You cannot
forbid other implementations to use asSam().

Just my .02€

Regards,
Alessio


More information about the lambda-dev mailing list