You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Jochen Theodorou (JIRA)" <ji...@apache.org> on 2016/02/03 13:20:39 UTC

[jira] [Commented] (GROOVY-7744) static import of multiple methods with same name

    [ https://issues.apache.org/jira/browse/GROOVY-7744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15130297#comment-15130297 ] 

Jochen Theodorou commented on GROOVY-7744:
------------------------------------------

expected? kind of. Groovy cannot resolve this kind of situation without static compilation. to know which method to use exactly, you need to know the signature of the call exactly as well. And that is an information that is currently not available in Groovy. With the ideas I have for Groovy 3 we might be able to resolve the problem, but in today's Groovy I see no chance. So what is the alternative? Leave it as is? Produce an error message? If we produce an error message, do we want to not do it if static compilation is in use?

> static import of multiple methods with same name
> ------------------------------------------------
>
>                 Key: GROOVY-7744
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7744
>             Project: Groovy
>          Issue Type: Improvement
>          Components: groovy-jdk
>    Affects Versions: 2.4.5
>            Reporter: Cazacu Mihai
>
> Hi,
> Please take a look at this code:
> {code:title=test.groovy|borderStyle=solid}
> import groovy.transform.CompileStatic
> import static A1.a // as a1
> import static A2.a // as a2
> import static A3.a // as a3
> @CompileStatic
> class A1 {
> 	static void a(String str) { println 'a1' }
> }
> @CompileStatic
> class A2 {
> 	static void a(int i) { println 'a2' }
> }
> @CompileStatic
> class A3 {
> 	static void a(boolean b) { println 'a3' }
> }
> a("string")
> a(1)
> a(true)
> {code}
> Running it, a compile exception is thrown:
> {quote}
> Caught: groovy.lang.MissingMethodException: No signature of method: static A3.a() is applicable for argument types: (java.lang.String) values: [string]
> Possible solutions: a(boolean), any(), any(groovy.lang.Closure), is(java.lang.Object), wait(), wait(long)
> groovy.lang.MissingMethodException: No signature of method: static A3.a() is applicable for argument types: (java.lang.String) values: [string]
> Possible solutions: a(boolean), any(), any(groovy.lang.Closure), is(java.lang.Object), wait(), wait(long)
> {quote}
> It seems that the latest import overwrites the previous ones.
> Is this the expected behavior in Groovy (Java allows this syntax)?
> Best regards,
> Mihai



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)