[ 
https://issues.apache.org/jira/browse/GROOVY-8098?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Sun reassigned GROOVY-8098:
----------------------------------

    Fix Version/s: 7.0.0-alpha-1
         Assignee: Daniel Sun

> Methods overloading issue
> -------------------------
>
>                 Key: GROOVY-8098
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8098
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Agata Strojewska
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 7.0.0-alpha-1
>
>
> 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
(v10.3.26#10030026)

Reply via email to