Skip to content

varargs ambiguity with generics #285

Description

@henridf
> var Arrays = java.import('java.util.Arrays');  
> var list = Arrays.asList(['a', 'b']);
> list.toArray();
[ [ 'a', 'b' ] ] // should be ['a', 'b'] !!

I haven't looked at the varargs handling code, but I'm assuming it's because of the ambiguity due to the asList method being generic (List<T> asList(T... a)) - there's no way to distinguish if the javascript Array being passed into Arrays.asList() is intended as a single value of type T or if it's intended as a T[].

Assuming that's the issue, we could detect this ambiguity and throw an error, requiring the javascript programmer to use apply when they want a javascript array to be 'spread' into a varargs generic function.

Does this make sense?

(Btw, ES6 compiled by babel works just fine here with Arrays.asList(...arr);).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions