You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Agata Strojewska (JIRA)" <ji...@apache.org> on 2017/02/22 10:58:44 UTC

[jira] [Created] (GROOVY-8098) Methods overloading issue

Agata Strojewska created GROOVY-8098:
----------------------------------------

             Summary: Methods overloading issue
                 Key: GROOVY-8098
                 URL: https://issues.apache.org/jira/browse/GROOVY-8098
             Project: Groovy
          Issue Type: Bug
            Reporter: Agata Strojewska


I've created a repository on Github with a simple example showing the problem: https://github.com/astrojewska/groovy-overloading-issue

There is a base repository interface with generic types:

{code:title=BaseRepository.java|borderStyle=solid}
public interface BaseRepository<T, S extends Serializable> {
    void call(T t);
    void call(S s);
}
{code}

And the specified:
{code:title=BaseSpecializedRepo.java|borderStyle=solid}
public interface BaseSpecializedRepo extends BaseRepository<Integer, String> {
}
{code}
Then I've created a class that implements BaseRepository<T, S>:
{code:title=InMemoryBaseRepo.java|borderStyle=solid}
public class InMemoryBaseRepo<T, S extends Serializable> implements BaseRepository<T, S> {
    public void call(T t) {
        System.out.println("T call");
    }

    public void call(S s) {
        System.out.println("S call");
    }
}
{code}
And another class that extends the previous one (in groovy):
{code:title=InMemorySpecializedGroovyRepo.groovy|borderStyle=solid}
class InMemorySpecializedGroovyRepo extends InMemoryBaseRepo<Integer, String> implements BaseSpecializedRepo {
}
{code}
Now I try to instantiate InMemorySpecializedGroovyRepo:
{code}
BaseSpecializedRepo groovyRepo = new InMemorySpecializedGroovyRepo()
{code}
And call:
{code}
groovyRepo.call(new Integer(0));
groovyRepo.call(new String("empty"));
{code}
At this point always method for <T> generic type is called.

Output:
{code}
### GROOVY ###
T call
T call

// java implementation: BaseSpecializedRepo javaRepo = new InMemorySpecializedJavaRepo()
### JAVA ###
T call
S call
{code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)