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

John Wagenleitner resolved GROOVY-7580.
---------------------------------------
       Resolution: Fixed
    Fix Version/s: 2.4.7

Thanks for reporting.  I have updated the docs to try to clarify that only 
existing declared methods on the class/interface will cause an exception and 
not methods added at runtime.

Updated wording is:

{quote}
Note that the left shift operator is used to append a new method. If a public 
method with the same name and parameter types is declared by the class or 
interface, including those inherited from superclasses and superinterfaces but 
excluding those added to the metaClass at runtime, an exception will be thrown. 
If you want to replace a method declared by the class or interface you can use 
the = operator.
{quote}

Commit 
https://github.com/apache/groovy/commit/1065954aafcb93da8258bbac6a0c9ce2397d99d9

> ExpandoMetaClass append method does not throw an exception as per docs
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-7580
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7580
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Aseem Bansal
>             Fix For: 2.4.7
>
>
> I was reading the docs when I came across "Note that the left shift operator 
> is used to append a new method. If the method already exists an exception 
> will be thrown."
> I decided to try it via the below program. There was no exception. I am using 
> groovy 2.3.8
> {noformat}
> class A {
> }
> A.metaClass.hello = {
>   "hello superclass"
> }
> class B extends A {
> }
> B.metaClass.hello << {
>   "hello subclass"
> }
> B.metaClass.hello << {
>   "hello subclass"
> }
> new B().hello()
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to