groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anand (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7883) Static compiler prefers private constructor over public if private matches better
Date Wed, 17 Aug 2016 10:10:20 GMT

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

Anand commented on GROOVY-7883:
-------------------------------

I believe this is how java compiler works. There is matching argument constructor  available
but  restricted through access modifier. By adding compileSatic groovy just bypass the meta
object protocol and the compilation is done in very regular java way. I think this compileStatic
is doing correctly. One way to test is convert this into java and then try to compile using
javac. I get the same error.

> Static compiler prefers private constructor over public if private matches better
> ---------------------------------------------------------------------------------
>
>                 Key: GROOVY-7883
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7883
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.7
>            Reporter: Jason Winnebeck
>
> When constructing an AssertionError for example, it has a public constructor taking Object
and a private constructor taking String. The static compiler "chooses" the private constructor
over the public one and this results in a compile error.
> {code}
> @groovy.transform.CompileStatic
> void doIt() {
>   //Cannot call private constructor for java.lang.AssertionError. However, it should
call AssertionError(Object)
>   throw new AssertionError("abc")
> }
> {code}



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

Mime
View raw message