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

Java Interop vs named & default arguments

1 reply
Kevin Wright
Joined: 2009-06-09,
User offline. Last seen 49 weeks 4 days ago.
Are any of the following even remotely possible?
  1. calling a java function from scala and using named arguments
  2. calling a scala function from java and using named arguments
  3. calling a scala function from java and using default arguments

Just "is it possible", not "is it easy and convenient with nice syntax"My guess is that 1 can't be done, 2 may be possible but would look uglier that calling overloaded operators, and 3 may just about be useable.

rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
Re: Java Interop vs named & default arguments


On Fri, Jul 10, 2009 at 07:57, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
Are any of the following even remotely possible?
  1. calling a java function from scala and using named arguments
  2. calling a scala function from java and using named arguments
  3. calling a scala function from java and using default arguments

1) no; java classfiles contain only argument types, not names2) no, javac does not see parameter names of scala classfiles, and   also there's no syntax in java for named arguments. 3) sort of. givenclass A {  def f[T](x: T)(y: T = x)}to use the default argument from java you'd need to do something like  A qualifier = getA();  String xArgument = getXArgument();   qualifier.f<String>(xArgument, qualifier.f$default$2<String>(xArgument))
The SID on named / default arguments explains how they're implemented.http://www.scala-lang.org/sid/1
Cheers: Lukas 

Just "is it possible", not "is it easy and convenient with nice syntax" My guess is that 1 can't be done, 2 may be possible but would look uglier that calling overloaded operators, and 3 may just about be useable.


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