You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2019/01/28 10:02:00 UTC

[jira] [Closed] (GROOVY-3358) static imports don't work for statically defined getters (property access)

     [ https://issues.apache.org/jira/browse/GROOVY-3358?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-3358.
-----------------------------

I'll close this as it seems to have been fixed earlier:
{code:java}
class Environment {
    private static INSTANCE
    static Environment getCurrentEnvironment() {
        if (INSTANCE == null) {
            INSTANCE = new Environment()
        }
    }
}

import static Environment.*

class Main {
    def method() {
        println currentEnvironment
    }
}

new Main().method()
{code}

> static imports don't work for statically defined getters (property access)
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-3358
>                 URL: https://issues.apache.org/jira/browse/GROOVY-3358
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: Compiler
>            Reporter: Graeme Rocher
>            Priority: Major
>
> So I have a class that defines:
> {code}
> public static Environment getCurrentEnvironment()
> {code}
> I use this class like:
> {code}
> import static grails.util.Environment.*
> {code}
> However this throws a MPE:
> {code}
> println currentEnvironment
> {code}
> whilst this works
> {code}
> println getCurrentEnvironment()
> {code}
> Seems wrong that propery notation should work for a static getter when it works when used directly:
> {code}
> import grails.util.Environment
> println Environment.currentEnvironment
> {code}



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