Scala compiler method bind problem for Java class, vararg vs. single object

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Scala compiler method bind problem for Java class, vararg vs. single object

manfred
Hi.

I have a problem where Scala code calls a different method on a Java class than Java does.

Take the following Java class:
public class Foo {

   
public void apply(Object ...foo) {
       
System.out.println("foo variable.");
   
}

   
public void apply(Object foo) {
       
System.out.println("foo single.");
   
}
}


Now, using this class from Scala and calling the apply method calls the variable argument version.

Using this class from Java the method with the single object argument is called.

This seems to be a different behavior in Scala whcih causes quite some trouble for a Java framework I'm using whcih gives a lot of unexpected behavior.

Is this behavior intentional or a bug?

This happens with Scala 2.11.8 as well as 2.12.1.


Manfred

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Scala compiler method bind problem for Java class, vararg vs. single object

manfred
Ah, sure I meant calling this method with a single argument.:
object FooUse extends App {
  val foo
= new Foo

  foo
.apply("use 1")
}

gives output:
"foo variale."

And this:
public class FooUse2 {
   
public static void main(String[] args) {
       
Foo foo = new Foo();

        foo
.apply("use 2");
   
}
}

gives output:
"foo single."


Manfred


Am Samstag, 18. Februar 2017 13:57:16 UTC+1 schrieb manfred:
Hi.

I have a problem where Scala code calls a different method on a Java class than Java does.

Take the following Java class:
public class Foo {

   
public void apply(Object ...foo) {
       
System.out.println("foo variable.");
   
}

   
public void apply(Object foo) {
       
System.out.println("foo single.");
   
}
}


Now, using this class from Scala and calling the apply method calls the variable argument version.

Using this class from Java the method with the single object argument is called.

This seems to be a different behavior in Scala whcih causes quite some trouble for a Java framework I'm using whcih gives a lot of unexpected behavior.

Is this behavior intentional or a bug?

This happens with Scala 2.11.8 as well as 2.12.1.


Manfred

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.