This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Is it possible to implement scala.Function2 in java?

3 replies
Guntis Ozols
Joined: 2011-05-10,
User offline. Last seen 42 years 45 weeks ago.

Is there any hope to implement scala.Function2 in java? How?
I'm interested in apply(T1, T2), but Function2 defines more than two
hundred methods - for example, curry$mcFDJ$sp() and so on.

Seth Tisue
Joined: 2008-12-16,
User offline. Last seen 34 weeks 3 days ago.
Re: Is it possible to implement scala.Function2 in java?

On Tue, Aug 2, 2011 at 6:46 PM, Guntis Ozols wrote:
> Is there any hope to implement scala.Function2 in java? How?
> I'm interested in apply(T1, T2), but Function2 defines more than two
> hundred methods - for example, curry$mcFDJ$sp() and so on.

scala.runtime.AbstractFunction2 exists for this purpose. (It's an
abstract class that extends the Function2 trait.)

ijuma
Joined: 2008-08-20,
User offline. Last seen 22 weeks 3 days ago.
Re: Is it possible to implement scala.Function2 in java?
On Wed, Aug 3, 2011 at 12:01 AM, Seth Tisue <seth [at] tisue [dot] net> wrote:
scala.runtime.AbstractFunction2 exists for this purpose.  (It's an abstract class that extends the Function2 trait.)

To be clear, AbstractFunction2 was introduced in order to reduce bytecode required for each anonymous functions (particularly in light of specialization). That is why it's in the scala.runtime package. A positive side-effect is that it helps implementations of Function2 in Java.
Best,Ismael
Guntis Ozols
Joined: 2011-05-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Is it possible to implement scala.Function2 in java?

Thanks, it works!

> > implement scala.Function2 in java? How?
>
> scala.runtime.AbstractFunction2

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland