You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2018/10/26 15:43:00 UTC

[jira] [Commented] (GROOVY-8856) Trait with generic will fail compilation if it has a static method that return the defined generic type.

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

Eric Milles commented on GROOVY-8856:
-------------------------------------

Isn't the type parameter {{T}} really an instance property of a class/trait?  That is, shouldn't a static method be specified this way since there is no way to fill in {{T}} without constructing an instance?

{code:groovy}
trait MyTrait {
  static <T extends List> T myMethod() {
    ...
  }
}
{code}

> Trait with generic will fail compilation if it has a static method that return the defined generic type.
> --------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-8856
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8856
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.5.0, 2.5.1, 2.5.2, 2.5.3
>         Environment: macOS 10.14
> OpenJDK 1.8.0_181-b02
>            Reporter: Dwi Elfianto
>            Priority: Blocker
>
> If you define a trait with generic type T and have a static method that return that type, compilation will fail with the following message:
> {code:java}
> Error:(5, 5) Groovyc: unable to resolve class T{code}
> Simple code for reproducing this bug:
> {code:java}
> trait MyTrait<T extends List> {
>     static T myMethod() {
>         return [1, 2, 3]
>     }
> }{code}
>  Groovy 2.4.x does not have this issue, from my testing this only happen in 2.5.x



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