Paul King commented on GROOVY-8479:

>From memory it was related to us not requiring {{plus}} to be homogeneous and 
>{{sum}} uses {{plus}} under the covers - apart from some special cases like 
>the {{int[]}} overload where some efficiencies are assumed.

def n1 = [1L, 2L, 3L]
def n2 = [1, 2, 3]
def n3 = ['a', 'b', 'c']

// types within collection determine result type
assert n1.sum(42) instanceof Long
assert n3.sum(42) instanceof String

// type of initial value determines result type
assert n2.sum(42L) instanceof Long
assert n2.sum(42) instanceof Integer
assert n2.sum('hi') instanceof String
But in general, anyone can defining any parameter types and return type for 

> sum from DefaultGroovyMethods does not have type information
> ------------------------------------------------------------
>                 Key: GROOVY-8479
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8479
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 2.4.13
>            Reporter: Michal Kordas
>            Priority: Major
> Overloads of {{org.codehaus.groovy.runtime.DefaultGroovyMethods#sum}} are 
> missing type information. I don't see {{@ClosureParams}} or generics on any 
> of them. 
> It should have been done in 
> https://issues.apache.org/jira/browse/GROOVY-7283, but for some reason 
> {{sum}} was not modified back then.

This message was sent by Atlassian JIRA

Reply via email to