[
https://issues.apache.org/jira/browse/GROOVY-5423?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-5423.
-----------------------------
> Wrong Method Being Invoked - Related To Static Imports
> ------------------------------------------------------
>
> Key: GROOVY-5423
> URL: https://issues.apache.org/jira/browse/GROOVY-5423
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 1.8.6, 2.4.0-beta-3
> Reporter: Jeff Brown
> Assignee: Eric Milles
> Priority: Major
> Labels: compiler
> Fix For: 2.5.1
>
> Attachments: staticimport.zip
>
>
> When a static import brings in a method which conflicts with a method defined
> in a class' super class Java invokes the method from the super class but
> Groovy invokes the method from the static import.
> {code:title=src/main/java/com/demo/Utils.java|borderStyle=solid}
> package com.demo;
> public class Utils {
>
> public static String getValue() {
> return "Utils.getValue";
> }
> }
> {code}
> {code:title=src/main/java/com/demo/MyBaseClass.java|borderStyle=solid}
> package com.demo;
> public class MyBaseClass {
>
> public static String getValue() {
> return "MyBaseClass.getValue";
> }
> }
> {code}
> {code:title=src/main/java/com/demo/JavaSubClass.java|borderStyle=solid}
> package com.demo;
> import static com.demo.Utils.*;
> public class JavaSubClass extends MyBaseClass {
>
> public String retrieveValue() {
> return getValue();
> }
> }
> {code}
> {code:title=src/main/groovy/com/demo/GroovySubClass.groovy|borderStyle=solid}
> package com.demo
> import static com.demo.Utils.*
> class GroovySubClass extends MyBaseClass {
>
> String retrieveValue() {
> getValue()
> }
> }
> {code}
> {code:title=src/test/groovy/com/demo/ImportTests.groovy|borderStyle=solid}
> package com.demo
> class ImportTests extends GroovyTestCase {
>
> void testJava() {
> def subClass = new JavaSubClass()
> def result = subClass.retrieveValue()
> assertEquals 'MyBaseClass.getValue', result
> }
>
> void testGroovy() {
> def subClass = new GroovySubClass()
> def result = subClass.retrieveValue()
> assertEquals 'MyBaseClass.getValue', result
> }
> }
> {code}
> The Java test passes but the Groovy test fails.
> To run the code download the attached project (staticimport.zip) and run
> "./gradlew test".
--
This message was sent by Atlassian Jira
(v8.20.1#820001)