You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Shil Sinha (JIRA)" <ji...@apache.org> on 2015/10/06 17:24:26 UTC

[jira] [Commented] (GROOVY-7370) Varargs in constructor are not treated correctly when creating instances of anonymous class

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

Shil Sinha commented on GROOVY-7370:
------------------------------------

This appears to happen because the parameters of synthetic constructors of anonymous classes which correspond to super parameters (i.e. not the super class or local variable references) have their types set as Object. When calling the super constructor, arguments are cast to the appropriate type; in this case 'manyLetters' is cast to String[] via ScriptBytecodeAdapter.castToType.

> Varargs in constructor are not treated correctly when creating instances of anonymous class
> -------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7370
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7370
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Nikita Artyushov
>
> Code snippet to reproduce the bug:
> {code}
> class Test {
>     public Test(String... args) {
>         println args
>     }
>     public static void main(String[] args) {
>         new Test('oneWord')
>         new Test('manyLetters') {
>             @Override
>             int hashCode() {
>                 return 1;
>             }
>         }
>     }
> }
> {code}
> expected output:
> {code}
> [oneWord]
> [manyLetters]
> {code}
> actual:
> {code}
> [oneWord]
> [m, a, n, y, L, e, t, t, e, r, s]
> {code}



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