Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: bytecode
-
Labels:None
-
Environment:Mac OSX 10.6, Java 6, Grails 1.3.3
-
Number of attachments :
Description
I was able to set a map variable declared as Map<Long, String> on a Java class to Map<String, String> from Groovy. As I understand it, Groovy should honor the strictly typed variables in Java.
I have provided a code sample to illustrate the problem.
Java Class:
public class MyJavaClass implements Serializable, Comparable<Object> { Map<Long, String> myMap = new HashMap()<Long, String>; }
Groovy Class:
class MyGroovyClass {
def populateMyMap(){
def values = [12345: "myString",67890: "my2ndString"] //Notice how the keys are Integers
def javaClass = new MyJavaClass()
def map = [:]
values?.each { k,v ->
map."$k" = v //Notice how the key is now a String
}
javaClass.myMap = map
return javaClass
}
}
Activity
Roshan Dawrani
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Description |
I was able to set a map variable declared as Map<Long, String> on a Java class to Map<String, String> from Groovy. As I understand it, Groovy should honor the strictly typed variables in Java.
I have provided a code sample to illustrate the problem. Java Class: public class MyJavaClass implements Serializable, Comparable<Object> { Map<Long, String> myMap = new HashMap()<Long, String>; } Groovy Class: class MyGroovyClass { def populateMyMap(){ def values = [12345: "myString",67890: "my2ndString"] //Notice how the keys are Integers def javaClass = new MyJavaClass() def map = [:] values?.each { k,v -> map."$k" = v //Notice how the key is now a String } javaClass.myMap = map return javaClass } } |
I was able to set a map variable declared as Map<Long, String> on a Java class to Map<String, String> from Groovy. As I understand it, Groovy should honor the strictly typed variables in Java.
I have provided a code sample to illustrate the problem. Java Class: {code} public class MyJavaClass implements Serializable, Comparable<Object> { Map<Long, String> myMap = new HashMap()<Long, String>; } {code} Groovy Class: {code} class MyGroovyClass { def populateMyMap(){ def values = [12345: "myString",67890: "my2ndString"] //Notice how the keys are Integers def javaClass = new MyJavaClass() def map = [:] values?.each { k,v -> map."$k" = v //Notice how the key is now a String } javaClass.myMap = map return javaClass } } {code} |