groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <>
Subject [jira] [Commented] (GROOVY-8350) Class expressions with and without ".class"
Date Sat, 14 Oct 2017 15:07:00 GMT


Eric Milles commented on GROOVY-8350:

I did some additional research on this one and answered a lot of my own questions.  Would
it be possible to update the language docs to reflect this (or point me to the section where
it is described)?

1. Class literals (with and without ".class") and class instances are interchangeable (at
least in dynamic Groovy); they all provide access to static members of the referent type
  {{System.getProperties()}}, {{System.class.getProperties()}}, and {{def systemClass = System
/*or any other source of class instance*/; systemClass.getProperties()}} all execute fine.

2. Point (1) extends to method pointers as well
  {{System.&currentTimeMillis}}, {{System.class.currentTimeMillis}}, and {{def systemClass
= ...;  systemClass.&currentTimeMillis}} all produce a usable closure.

3. Point (1) extends to property syntax as well
  {{}}, {{}}, and {{def systemClass = ...;}}
should all call {{System.getProperties()}}

4. Point (1) extends to Class members
  {{System.getCanonicalName()}}, {{System.class.getCanonicalName()}} and {{def systemClass
= ...;  systemClass.getCanonicalName()}} all return "java.lang.System"

5. Class static methods can be called directly from static initializers
  class C {
    static {
      def name = getCanonicalName() // equivalent to C.getCanonicalName()

> Class expressions with and without ".class"
> -------------------------------------------
>                 Key: GROOVY-8350
>                 URL:
>             Project: Groovy
>          Issue Type: Documentation
>            Reporter: Eric Milles
>            Priority: Minor
> This seems like a bug (but it could just be a clarification in the documentation).  And
is seems related to GROOVY-8152, GROOVY-8153, and GROOVY-8154.
> {{System.currentTimeMillis()}} is your typical static call.
> {{System.getClass().currentTimeMillis()}} results in a MissingMethodException, as it
> However, {{System.class.currentTimeMillis()}} and {{def sys = System.class; sys.currentTimeMillis()}}
both compile and execute fine.  I would expect a MissingMethodException for these as well.
> Is there some trick where methodMissing on class instance can find the static method
or something?  My Java experience says no {{currentTimeMillis}} method on {{Class}}.

This message was sent by Atlassian JIRA

View raw message