- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Java Interop vs named & default arguments
Fri, 2009-07-10, 06:57
Are any of the following even remotely possible?
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.
- calling a java function from scala and using named arguments
- calling a scala function from java and using named arguments
- 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.
On Fri, Jul 10, 2009 at 07:57, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
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