String[] java interop issue

40 views
Skip to first unread message

jpr...@free.fr

unread,
May 2, 2013, 5:43:58 AM5/2/13
to ceylon...@googlegroups.com
Hi all,

I'm trying to pass a String[] to a java method (to fill a SWT Combo), but the method described in the doc seems broken:

// Java
public class JavaType {
    public void takeThisArray(String[] arr){}
}

// Ceylon
void doTest() {
    JavaType t = JavaType();
    Array<String> a = array({"One", "Two", "Three"});
    t.takeThisArray(a);
}

The compiler reports:
  argument must be assignable to parameter arr of takeThisArray: Array<String> is not assignable to ObjectArray<String>?

NB: I added braces to array() arguments.

Any idea ?

Stephane Epardaud

unread,
May 2, 2013, 5:49:11 AM5/2/13
to ceylon...@googlegroups.com
Arg, yes I need to update the docs, I'll do it right away sorry about that. You should try:

import java.lang { ObjectArray, arrays }

void doTest() {
    JavaType t = JavaType();
    ObjectArray<String> a = arrays.toJavaStringArray{"One", "Two", "Three"};
    t.takeThisArray(a);
}


--
You received this message because you are subscribed to the Google Groups "ceylon-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-users...@googlegroups.com.
To post to this group, send email to ceylon...@googlegroups.com.
Visit this group at http://groups.google.com/group/ceylon-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Stéphane Épardaud

jpr...@free.fr

unread,
May 2, 2013, 6:01:25 AM5/2/13
to ceylon...@googlegroups.com

jpr...@free.fr

unread,
May 2, 2013, 6:09:23 AM5/2/13
to ceylon...@googlegroups.com
Well, I supposed this method was quite new, so I updated ceylon to git head, but now it doesn't compile - ceylon-sdk compilation fails...
(and sorry for last (empty) message, it was a dummy click).

Stephane Epardaud

unread,
May 2, 2013, 6:11:48 AM5/2/13
to ceylon...@googlegroups.com
No don't worry the code I gave you works on M5.

jpr...@free.fr

unread,
May 2, 2013, 8:30:31 AM5/2/13
to ceylon...@googlegroups.com
Well, I just tried this code on ceylon 0.5 (fresh install in a fresh VM), and the compiler complained:

/home/jpragey/workspace/CeylonTest/source/org/jpragey/test/run.ceylon:6: error: specified expression must be assignable to declared type of a: java.lang::ObjectArray<java.lang::String> is not assignable to java.lang::ObjectArray<ceylon.language::String>

    ObjectArray<String> a = arrays.toJavaStringArray{"One", "Two", "Three"};
                          ^
/home/jpragey/workspace/CeylonTest/source/org/jpragey/test/run.ceylon:7: error: argument must be assignable to parameter arr of takeThisArray: ObjectArray<String> is not assignable to ObjectArray<String>?
    t.takeThisArray(a);

Stephane Epardaud

unread,
May 2, 2013, 8:34:26 AM5/2/13
to ceylon...@googlegroups.com
Sorry let's try again:

import java.lang { ObjectArray, arrays, JavaString = String }

void doTest() {
    JavaType t = JavaType();
    ObjectArray<JavaString> a = arrays.toJavaStringArray{"One", "Two", "Three"};
    t.takeThisArray(a);
}

jpr...@free.fr

unread,
May 2, 2013, 8:46:32 AM5/2/13
to ceylon...@googlegroups.com
Cool! It works in 0.5 and (more or less current) git head.
Thanks Stéphane!

Stephane Epardaud

unread,
May 2, 2013, 8:56:23 AM5/2/13
to ceylon...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages