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