Skip to content

cannot overload a java method with optional arguments #1953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scabug opened this issue May 4, 2009 · 3 comments
Closed

cannot overload a java method with optional arguments #1953

scabug opened this issue May 4, 2009 · 3 comments

Comments

@scabug
Copy link

scabug commented May 4, 2009

using 2.7.4-final, i cannot implement an abstract java method with optional arguments. the compiler says it's all fine and compiles without errors, but the program doesn't run.

ABaseJavaClass.java---------------------

package com.razie.learnscala;

public abstract class ABaseJavaClass {

public abstract void takesOptionalArgs (String...args);
public abstract void takesMoreOptionalArgs (String...args);
}

AScalaExtension.scala--------------------

class AScalaExtension extends ABaseJavaClass {
override def takesOptionalArgs (x:String*) = {
java.lang.System.out.printf ("Java printf: %s %s %s", x:_*)
}
}

object LearnScala extends Application {
val cc : ABaseJavaClass = (new AScalaExtension)
cc.takesOptionalArgs ("itsi", "bitsi", "spider")
}

      - runtime output:

Exception in thread "main" java.lang.AbstractMethodError: com.razie.learnscala.ABaseJavaClass.takesOptionalArgs([Ljava/lang/String;)V
at com.razie.learnscala.LearnScala$$.(LearnScala.scala:7)
at com.razie.learnscala.LearnScala$$.(LearnScala.scala)
at com.razie.learnscala.LearnScala.main(LearnScala.scala)

expected output:------------
Java printf: itsi bitsi spider

---------------------additional info

the method signatures in the .class files are different. the scala version takes a (Lscala/Seq;) while the java version takes ([Ljava/lang/String;)

@scabug
Copy link
Author

scabug commented May 4, 2009

Imported From: https://issues.scala-lang.org/browse/SI-1953?orig=1
Reporter: Razvan Cojocaru (razie)

@scabug
Copy link
Author

scabug commented May 4, 2009

Razvan Cojocaru (razie) said:
sorry - just ignore this second method in the java class - i was playing with other options:

public abstract void takesMoreOptionalArgs (String...args);

@scabug
Copy link
Author

scabug commented May 4, 2009

@paulp said:
This is a duplicate of #1459.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant