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

Eric Milles updated GROOVY-8121:
--------------------------------
    Description: 
I have been looking at Cateogry methods and noticed that one of the edge cases 
is that of a tie between a category method and an instance method.  Could you 
add a clarification to the docs how this case is handled?
http://groovy-lang.org/metaprogramming.html#categories

It appears from my testing that if there is a tie between a category method and 
an instance method, the category method is chosen at runtime.
Example:
{code}
class Cat {
  static void meth(Main m) {}
}

class Main {
  void meth() {
    use (Cat) {
      meth() // this appears to be a call to Cat.meth
      this.meth() // this appears to be a call to Cat.meth
      this.meth // this appears to be a reference to Cat.meth
      // is there a way in this block to explicitly choose Main.meth ?
    }
  }
}
{code}

Also, does this rule hold up under TypeChecked or CompileStatic?

Lastly, default groovy methods seem related.  I think if there is a tie between 
a default groovy method and an instance method, the instance method is 
preferred.  I checked this with List.sort(Comparator), which is now available 
in Java 8.

Is the difference of preferring the category method in one case and the 
instance method in the other case intended?  I would prefer the instance method 
be selected in both cases.

  was:
I have been looking at Cateogry methods and noticed that one of the edge cases 
is that of a tie between a category method and an instance method.  Could you 
add a clarification to the docs how this case is handled?
http://groovy-lang.org/metaprogramming.html#categories

It appears from my testing that if there is a tie between a category method and 
an instance method, the category method is chosen at runtime.
Example:
{code}
class Cat {
  static void meth(Main m) {}
}

class Main {
  void meth() {
    use (Cat) {
      meth() // this appears to be a call to Cat.meth
      this.meth() // this appears to be a call to Cat.meth
      this.meth // this appears to be a reference to Cat.meth
      // is there a way in this block to explicitly choose Main.meth ?
    }
  }
}
{code}

Also, does this rule hold up under TypeChecked or CompileStatic?

Lastly, default groovy methods seem related.  I think if there is a tie between 
a default groovy method and an instance method, the instance method is 
preferred.  I checks this with List.sort(Comparator), which is now available in 
Java 8.

Is the difference of preferring the category method in one case and the 
instance method in the other case intended?  I would prefer the instance method 
be selected in both cases.


> Clarification on selection of category method or instance method in case of a 
> tie
> ---------------------------------------------------------------------------------
>
>                 Key: GROOVY-8121
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8121
>             Project: Groovy
>          Issue Type: Question
>          Components: Documentation
>            Reporter: Eric Milles
>            Priority: Minor
>
> I have been looking at Cateogry methods and noticed that one of the edge 
> cases is that of a tie between a category method and an instance method.  
> Could you add a clarification to the docs how this case is handled?
> http://groovy-lang.org/metaprogramming.html#categories
> It appears from my testing that if there is a tie between a category method 
> and an instance method, the category method is chosen at runtime.
> Example:
> {code}
> class Cat {
>   static void meth(Main m) {}
> }
> class Main {
>   void meth() {
>     use (Cat) {
>       meth() // this appears to be a call to Cat.meth
>       this.meth() // this appears to be a call to Cat.meth
>       this.meth // this appears to be a reference to Cat.meth
>       // is there a way in this block to explicitly choose Main.meth ?
>     }
>   }
> }
> {code}
> Also, does this rule hold up under TypeChecked or CompileStatic?
> Lastly, default groovy methods seem related.  I think if there is a tie 
> between a default groovy method and an instance method, the instance method 
> is preferred.  I checked this with List.sort(Comparator), which is now 
> available in Java 8.
> Is the difference of preferring the category method in one case and the 
> instance method in the other case intended?  I would prefer the instance 
> method be selected in both cases.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to