Scala arrays appear as scala Array type in java
Migrated from http://lampsvn.epfl.ch/trac/scala/ticket/1645
Reporter CadErik
in scala
class MyClass {
def myFunc(arg: Array[T]) {
...
}
}
in the JDT the array shows in a java class as Array instead of T[]
Reporter CadErik
in scala
class MyClass {
def myFunc(arg: Array[T]) {
...
}
}
in the JDT the array shows in a java class as Array instead of T[]
Leave a comment
on 2010-06-08 23:38 *
By Ramnivas Laddad
It will be really nice to see this fixed, since this is a show stopper while migrating from Java
on 2010-06-09 01:21 *
By
How is this a show stopper?
on 2010-06-09 23:27 *
By Ramnivas Laddad
I get an error in Java source file stating "missing Array type" (for example, when a Scala class returning Array[SomeClass] and Java source file expected SomeClass[]). Not sure how to proceed after that (short of converting that file to Scala as well, which I will do in time, but just not yet). Please let me know if I missed something or if there is another way.
on 2010-06-10 07:18 *
By
Scala's Array[SomeClass] is exactly the same type as Java's SomeClass[], so I think you must be misinterpreting the error that you're seeing.
I suggest trying a very small mixed Scala/Java example using command line scalac ... once you have that working correctly it will also work correctly in Eclipse.
I suggest trying a very small mixed Scala/Java example using command line scalac ... once you have that working correctly it will also work correctly in Eclipse.
on 2010-06-10 18:25 *
By Ramnivas Laddad
I know that they are exactly the same and 'scalac' works just fine. The problem is Scala IDE thinks otherwise. Here is what I tried:
// bug/ScalaClass.scala
package bug
class ScalaClass {
def methodThatReturnsStringArray() : Array[String] = {
null
}
}
// bug/JavaClass.java
package bug;
public class JavaClass {
public void foo() {
ScalaClass sc = new ScalaClass();
String[] sArray = sc.methodThatReturnsStringArray();
System.out.println(sArray);
}
}
> scalac bug/ScalaClass.scala bug/JavaClass.java
> javac -classpath $SCALA_HOME/lib/scala-library.jar:target/classes:. bug/JavaClass.java
No errors...
Now the same project in Eclipse gives the following error in the editor (with Plugin version 2.8.0.r22118-b20100602025655)
Type mismatch: cannot convert Array to String[]
for the following line
String[] sArray = sc.methodThatReturnsStringArray();
Note that this is better than what I observed earlier with an older nightly build. Now only the editor is in error. So no longer a show stopper, but annoying nevertheless.
// bug/ScalaClass.scala
package bug
class ScalaClass {
def methodThatReturnsStringArray() : Array[String] = {
null
}
}
// bug/JavaClass.java
package bug;
public class JavaClass {
public void foo() {
ScalaClass sc = new ScalaClass();
String[] sArray = sc.methodThatReturnsStringArray();
System.out.println(sArray);
}
}
> scalac bug/ScalaClass.scala bug/JavaClass.java
> javac -classpath $SCALA_HOME/lib/scala-library.jar:target/classes:. bug/JavaClass.java
No errors...
Now the same project in Eclipse gives the following error in the editor (with Plugin version 2.8.0.r22118-b20100602025655)
Type mismatch: cannot convert Array to String[]
for the following line
String[] sArray = sc.methodThatReturnsStringArray();
Note that this is better than what I observed earlier with an older nightly build. Now only the editor is in error. So no longer a show stopper, but annoying nevertheless.
Thanks for your persistence. I'm also seeing the error in the editor.
This is a bug in the presentation compiler only and, as you noted, there is no build error shown in the Problems view ... the Scala and Java source are compiled successfully.
This is a bug in the presentation compiler only and, as you noted, there is no build error shown in the Problems view ... the Scala and Java source are compiled successfully.
Updating tickets (#1000069, #1000195, #1000213, #1000223, #1000006, #1000021, #1000038, #1000048, #1000051, #1000052, #1000075, #1000103, #1000109, #1000115, #1000119, #1000156, #1000186, #1000207, #1000238, #1000262, #1000263, #380, #389, #683, #1238, #1331, #1635, #1645, #1715, #1729, #1744, #1783, #1839, #1869, #1885, #1890, #1902, #1918, #1919, #1924, #1925, #1946, #1964, #1991, #2131, #2233, #2342, #2348, #2408, #2459, #2499, #2523, #2572, #2582, #2602, #2614, #2615, #2675, #2710, #2745, #2763, #2816, #2830, #2834, #2878, #2879, #2887, #2888, #2901, #2911, #2912, #2922, #2937, #2938, #2942, #2951, #2955, #2957, #2961, #2964, #2965, #2974, #2975, #2989, #2990, #3002, #3055, #3070, #3087, #3135, #3139, #3173, #3182, #3184, #3200, #3213, #3214, #3221, #3243, #3251)
on 2011-03-24 17:18 *
By Iulian Dragos
Updating tickets (#1000199, #1000200, #1000201, #1000204, #1000205, #1000209, #1000210, #1000211, #1000212, #1000215, #1000217, #1000218, #1000220, #1000222, #1000226, #1000227, #1000228, #1000230, #1000231, #1000232, #1000233, #1000235, #1000236, #1000237, #1000239, #1000240, #1000241, #1000242, #1000243, #1000244, #1000248, #1000249, #1000252, #1000253, #1000254, #1000255, #1000256, #1000258, #1000259, #1000032, #1000059, #1000062, #1000163, #1000197, #1000216, #1000221, #1000224, #1000121, #1000175, #1000219, #1000251, #1000069, #1000195, #1000213, #1000223, #1000006, #1000021, #1000038, #1000048, #1000051, #1000052, #1000075, #1000103, #1000109, #1000115, #1000119, #1000156, #1000186, #1000207, #1000238, #1000262, #1000263, #380, #389, #683, #1238, #1331, #1635, #1645, #1715, #1729, #1744, #1783, #1839, #1869, #1885, #1890, #1902, #1918, #1919, #1924, #1925, #1946, #1964, #1991, #2131, #2233, #2342, #2348, #2408)
Closing as invalid.
I cannot reproduce the problem on both 2.0.0-2.9 and master-2.10. This has likely been fixed during 2.0 development (likely a fix on the structure builder).
Please reopen with additional information if you still see the problem.
I cannot reproduce the problem on both 2.0.0-2.9 and master-2.10. This has likely been fixed during 2.0 development (likely a fix on the structure builder).
Please reopen with additional information if you still see the problem.