Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
-
Number of attachments :
Description
The script:
number = 27 println number.toHexString ( )
results in the message:
Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.toHexString() is applicable for argument types: () values: []
Possible solutions: toHexString(int), toString(), toString(), toString(), toString(int), toString(int, int)
groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.toHexString() is applicable for argument types: () values: []
Possible solutions: toHexString(int), toString(), toString(), toString(), toString(int), toString(int, int)
at toHexString_Problem.run(toHexString_Problem.groovy:5)
The reason is that toHexString is defined as a static method on the types and not within the GroovyJDK. I believe that it is more usable for prograqmmers, more appropriate to a dynamic language, and generally more Groovy to allow the method to operate on a reference to an object and only raise an exception if the object is not of an appropriate type.
Not sure it's a bug since I don't think groovy ever claimed to support this feature. Can you elaborate a bit more on what you are proposing? Are you suggesting that Groovy should assume for an instance of some class, that any static method that happens to have the class type as its first parameter should be added as an instance "meta-method" for the class? I.e. "static toHexString(Integer param)" and possibly "static toHexString(int param)" would be treated as instance methods on any Integer but "static parseInt(String param)" would not because while being a static method in the Integer class doesn't have Integer as its first param?