Generics Signature is invisible from java source editor
I installed Scala IDE for Eclipse and create sources below.
Then I got unexpected compile error on GenTest at line 4.
'Type mismatch: cannot convert from element type Object to String'
But Generics Signature check program below output 'java.util.List<java.lang.String>'
It seems Scala compiler correctly generate .class with generics signature but Scala Plug-in not.
Eclipse Java EE IDE for Web Developers - Build id: 20100218-1602 (Galileo)
Scala IDE for Eclipse - 2.8.0.final
// Test.scala
case class Test { var list : java.util.List[String] = null }
// GenTest.java
public class GenTest {
public void test() {
Test test = new Test();
for (String item : test.list() ) {
System.out.println(item);
}
}
}
Then I got unexpected compile error on GenTest at line 4.
'Type mismatch: cannot convert from element type Object to String'
for (String item : test.list() ) {
But Generics Signature check program below output 'java.util.List<java.lang.String>'
// CheckReturnType.java
public class CheckReturnType {
public static void main(String[] args) throws Exception {
System.out.println(Test.class.
getMethod("list").getGenericReturnType() );
}
}
It seems Scala compiler correctly generate .class with generics signature but Scala Plug-in not.
Eclipse Java EE IDE for Web Developers - Build id: 20100218-1602 (Galileo)
Scala IDE for Eclipse - 2.8.0.final
Leave a comment
on 2010-08-17 11:30 *
By kazuhiko.arase
Description changed from I installed Scala IDE for E... to I installed Scala IDE for E...
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 14: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)
Hi,
This ticket currently resides in the backlog, do you perhaps have an indication for me when this ticket will be scheduled?
In the recently released beta11 quite some Java-Scala interoperability issues were solved (nice!), but this particular issue still exists.
In another similar ticket a workaround was proposed by using a "@SuppressedWarnings("unchecked")" annotation but this gives an error "Type mismatch: cannot convert from Map<String,Object> to Map<String,Short>" for "Returner.returnMap()" in the following code:
A workaround for this error is to first assign the value of the return statement to a separate variable which is a raw map and to return this value, but this requires another "SuppressedWarnings" annotation for "rawtypes" usage.:
Having to do this for all Java calls to Scala methods which have generics in their signatures is not very clean in my opinion, as it can obscure other (valid) warnings in the same method.
This ticket currently resides in the backlog, do you perhaps have an indication for me when this ticket will be scheduled?
In the recently released beta11 quite some Java-Scala interoperability issues were solved (nice!), but this particular issue still exists.
In another similar ticket a workaround was proposed by using a "@SuppressedWarnings("unchecked")" annotation but this gives an error "Type mismatch: cannot convert from Map<String,Object> to Map<String,Short>" for "Returner.returnMap()" in the following code:
package com.reproduction
import scala.collection.JavaConversions._
object Returner
{
def returnMap =
{
val map: Map[String,Short] = Map.empty
mapAsJavaMap(map)
}
}
package com.reproduction;
import java.util.Map;
public class Caller
{
@SuppressWarnings("unchecked")
public Map<String,Short> call()
{
return Returner.returnMap();
}
}
A workaround for this error is to first assign the value of the return statement to a separate variable which is a raw map and to return this value, but this requires another "SuppressedWarnings" annotation for "rawtypes" usage.:
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map<String,Short> call()
{
Map returnValue = Returner.returnMap();
return returnValue;
}
Having to do this for all Java calls to Scala methods which have generics in their signatures is not very clean in my opinion, as it can obscure other (valid) warnings in the same method.
on 2011-10-05 04:13 *
By Mirco Dotta
Version changed from 2.8.0.final to 2.0.0-beta11-29
Eclipse version changed from Galileo to Helios
Assigned to changed from login to Mirco Dotta
Component changed from None to JDT integration
Priority changed from High (2) to Normal (3)