Overloaded Methods with Collection Arguments

38 views
Skip to first unread message

danci...@gmail.com

unread,
Jun 21, 2013, 3:11:29 PM6/21/13
to gwtex...@googlegroups.com
I see other discussions here about method overloading in general and it seems to work fine in most cases.
I've got a class that has an overloaded method taking a collection as first parameter like below:

    @Export
    public void foo(Collection<Integer> arr, String a){
    logger.log(Level.FINEST, "called with 2 params");
    foo(arr, a, "otherstring");
    }
    @Export
    public void foo(Collection<Integer> arr, String a, String b){
    logger.log(Level.FINEST, "called with 3 params");
    }

Calling either of the above methods from JavaScript results in "Can't find exported method for given arguments: 1:3".
Can easily work around the problem by either: 
  • exporting only one of the functions
  • renaming one of the functions in Java
  • renaming one of the functions via @Export("foo2")

Manolo admits there may be some edge cases. Is this one such case? Despite the workaround I'd still like to understand "why" this happens.  Is there something happening here where the array-list backed Collection is being interpreted as the arguments array?

Manuel Carrasco Moñino

unread,
Jul 2, 2013, 3:56:32 AM7/2/13
to gwtex...@googlegroups.com
How do you call your exported 'foo' methods from javascript to pass a
java collection?
Are you aware that Collections are not supported by gwt-exporter [1]?

In your case this should work:

@Export
public void foo(int[] arr, String a){
logger.log(Level.FINEST, "called with 2 params");
foo(arr, a, "otherstring");
}
@Export
public void foo(int[] arr, String a, String b){
logger.log(Level.FINEST, "called with 3 params");
}


myInstance.foo([1,2], "a");
myInstance.foo([1,2], "a", "b");



[1] http://code.google.com/p/gwt-exporter/wiki/GettingStarted#Exportable_types
> --
> Has recibido este mensaje porque estás suscrito al grupo "gwtexporter" de
> Grupos de Google.
> Para anular la suscripción a este grupo y dejar de recibir sus correos
> electrónicos, envía un correo electrónico a
> gwtexporter...@googlegroups.com.
> Para obtener más opciones, visita https://groups.google.com/groups/opt_out.
>
>

danci...@gmail.com

unread,
Jul 2, 2013, 9:38:41 AM7/2/13
to gwtex...@googlegroups.com
Right I should have clarified. In my particular case, the collection is returned from another method, and just passed around as an opaque object in my JavaScript code. So it would be like this:

var c = myInstance.getC(); //Returns the Java collection
myInstance.foo(c, "a"); 
myInstance.foo(c, "a", "b"); 

I am aware that collections aren't supported by gwt-exporter. Is my understanding wrong about using Collections and Lists as opaque objects. Is that also not supported?
Reply all
Reply to author
Forward
0 new messages