Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.7.8, 1.8.1
-
Fix Version/s: 1.8.2, 1.9-beta-3
-
Component/s: None
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
When I static import a method, it takes precedence over a call to the method explicitly on another class, if I get a property from the result.
$ cat Foo.groovy
class Foo {
static doIt() { [k: 'foo'] }
}
jbeutel@jbeutel-mac:~/proj/groovySandboxes/staticImports (master *)
$ cat Bar.groovy
import static Foo.*
class Bar {
static doIt() { [k: 'bar'] }
static doAssert() {
assert doIt().k == 'foo'
assert doIt() == [k: 'foo']
assert Bar.doIt() == [k: 'bar']
assert Bar.doIt().k == 'bar'
}
}
jbeutel@jbeutel-mac:~/proj/groovySandboxes/staticImports (master *)
$ groovy -e 'Bar.doAssert()'
Caught: Assertion failed:
assert Bar.doIt().k == 'bar'
| |
| false
foo
Assertion failed:
assert Bar.doIt().k == 'bar'
| |
| false
foo
at Bar.doAssert(Bar.groovy:8)
at Bar$doAssert.call(Unknown Source)
at script_from_command_line.run(script_from_command_line:1)
jbeutel@jbeutel-mac:~/proj/groovySandboxes/staticImports (master *)
$ groovy --version
Groovy Version: 1.8.1 JVM: 1.6.0_26
This was a problem for me when statically importing (with wildcards) a bunch of enum classes into another enum.
Work-around: assign the method result to a temporary variable before getting a property from it.