groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: Overload resolution and CompileStatic
Date Fri, 04 Nov 2016 18:22:30 GMT
On 04.11.2016 18:49, alejes wrote:
> Hi all,
>
> I experimented with overload resolution. And faced with two such examples:
[...]
> To summarize, when using CompileStatic, we are seeing a call to another
> method.
> It is a bug or feature? If this feature, you can comments why it was decided
> to do?

my simpler version:

> def foo(Object x){1}
> def foo(String x){2}
> def create(){ return "" }
>
> @CompileStatic
> def bar() {
>   assert foo("") == 2
>   assert foo(new Object()) == 1
>   assert foo(create()) == 1
> }
>
> bar()

The reasons simply being, that because create is declared with Objet 
(def), it is seen as something that will return Object and not String. 
Thus foo(Object) is used instead of foo(String). Yes we do type 
inference, but this is basically only for local variables.

bye Jochen

Mime
View raw message