Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7772

Class.&instanceMethod had better to have same meaning of Class::instanceMethod of Java8

    Details

    • Type: Improvement
    • Status: Reopened
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.4.6
    • Fix Version/s: 2.6.0-alpha-1
    • Component/s: groovy-runtime
    • Labels:
      None

      Description

      Groovy's operator .& for method is similar functionality to Java8's method reference operator ::.

      No. lhs rhs meaing of Groovy's .& (Closure) meaning of java8's :: (FunctionalInterface)
      1 instance instanceMethod { ..args -> instance.instanceMethod(args) same as groovy
      2 Class staticMethod { ..args -> Class.staticMethod(args) same as groovy
      3 instance staticMethod ERROR groovy.lang.MissingMethodException: Error same as groovy (compile error)
      4 Class instanceMethod error Function<RetType,Class,Args..>, where method instance method of Class which is declared as ```RetType instanceMethod(Args..) {...}

      ```. In other words it is interpreted as a function which takes LHS Class as the first parameter which additionally inserted to the method.)

      IMHO, i'd like to propose to change the No 4 pattern semantics of groovy same as Java 8 's. Because:

      • You can write:
        ["a,b,c"].collect ( String.&toUpperCase )
        

        instaed of

        ["a,b,c"].collect { it.toUpperCase() }
        
      • Can have correspond operator to java8's ::. which is understandablea and needed for Java programmers.

        Attachments

          Activity

            People

            • Assignee:
              daniel_sun Daniel Sun
              Reporter:
              uehaj UEHARA Junji
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: