groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8454) Method with wrong argument typed is called when passing 'null'
Date Mon, 22 Jan 2018 00:16:12 GMT

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

Paul King commented on GROOVY-8454:
-----------------------------------

True. I think we could document our definition of "more general" though. Currently in the
doc we say "TBD" for 'Method selection algorithm'. There are several bits to document for
this bit perhaps explaining why we get these results would make it clearer:
{noformat}
String/Map => Map is more general
String/Integer => String is more general
String/Date => GroovyRuntimeException: Ambiguous method ...
{noformat}
Or can you think of some better examples?

> Method with wrong argument typed is called when passing 'null'
> --------------------------------------------------------------
>
>                 Key: GROOVY-8454
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8454
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.3
>            Reporter: Marek Baluch
>            Assignee: Jochen Theodorou
>            Priority: Major
>
> The output of the following code is 'Map:  null' instead of 'String: null'
> {code:java}
> class Stat {
>     def static m(String s) {
>         println 'String: ' + s
>     }
>     def static m(Map m) {
>         println 'Map: ' + m
>     }
> }
> class Main {
>     def run() {
>         String n = null
>         Stat.m(n)
>     }
>     def static void main(String ... args) {
>         new Main().run()
>     }
> }
> {code}
> To get the correct output I must explicitly cast the null value to String.
> {code:java}
> Stat.m((String)n)
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message