Skip to content
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

There should be a way of generating a Java-style varargs method signature from a Scala sequence method #3621

Closed
scabug opened this issue Jun 29, 2010 · 9 comments

Comments

@scabug
Copy link

scabug commented Jun 29, 2010

If I declare a method in a class in "scala-sequence" style:

    def foo(args: String*) : Unit

And inspect the generated class file (as if it had been generated from a Java class), the signature looks like:

    public void foo(scala.collection.Seq<java.lang.String> p0)

I think that, for interop with Java, it would be nice if we could generate a Java varargs method signature (that is, taking a String array with the transient modifier set):

    public transient void foo(java.lang.String[] p0)

I tried adding the @transient annotation but this was ignored by scalac!

I would ask for either:

  1. The compiler automatically generates Java varargs-style "forwarder" methods for Scala sequence ones

  2. A @VarArgs annotation is supplied, which, when used in conjunction with a scala-sequence method, generates a Java varargs forwarder as in Scaladoc NullPointerException #1

Chris

@scabug
Copy link
Author

scabug commented Jun 29, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3621?orig=1
Reporter: @oxbowlakes

@scabug
Copy link
Author

scabug commented Jun 29, 2010

@oxbowlakes said:
Oops - sorry for the bad link to the first bullet point

@scabug
Copy link
Author

scabug commented Nov 23, 2010

@axel22 said:
Working on it.

One thing troubles me, though. Why do you want to mark the method as transient? Looking through the Java language and vm specifications, and browsing all around the net, I couldn't find a reference for the transient modifier being applied to methods and what that means.

@scabug
Copy link
Author

scabug commented Nov 23, 2010

@oxbowlakes said:
As far as I was aware, Java used the transient modifier within the bytecode to mark a method which takes an array as being a varargs method.

I now cannot find any reference to this, so I am presumably wrong. However, IDEA will mark a varargs method in a class file as being "transient", so perhaps that's the source of the issue.

@scabug
Copy link
Author

scabug commented Nov 23, 2010

@oxbowlakes said:
I take it all back - this is easily testable as follows:

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class VarargsTest {
public static void main(String[] args) {
for (Method method : VarargsTest.class.getDeclaredMethods()) {
System.out.println(method.getName() + " " + ((method.getModifiers() & Modifier.TRANSIENT) > 0 ? "TRANSIENT" : ""));
}

}

public static void foo(String[] ss) {
    System.out.println("ss = " + ss);
}

public static void bar(String... s) {
    System.out.println("s = " + s);
}

}

@scabug
Copy link
Author

scabug commented Nov 23, 2010

@axel22 said:
Interesting. In fact, I was wrong - it seems to be documented here:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6516895

Ok, then so be it.

@scabug
Copy link
Author

scabug commented Nov 29, 2010

@dcsobral said:
Wasn't this closed by r23578?

@scabug
Copy link
Author

scabug commented Nov 30, 2010

@axel22 said:
I'm still waiting for the review.

@scabug
Copy link
Author

scabug commented Mar 27, 2011

@paulp said:
I reckon that's all the reviewin' we're gettin'.

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

2 participants