[ https://issues.apache.org/jira/browse/GROOVY-7869?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15344090#comment-15344090 ]
Paul King commented on GROOVY-7869: ----------------------------------- Reducing priority a bit since there is a known workaround. I won't close just yet. If the priority isn't documented at least, then we should at least remedy that. Wrt bug or feature. The current behavior is "as by design" but I haven't checked whether every approach for adding methods, e.g. contrasting with EMC for instance, yields exactly the same result. So, if we do ever come out with our revised MOP, we might tidy things up a bit. But that will be a well publicized happening, e.g. Groovy 3.0 and any changes would be documented. Wrt 2.2.x behavior. I don't think priority order changed around that time. My suspicion is a DGM method for plus on Iterable was added. > Groovy category does now work with abstract iterable classes > ------------------------------------------------------------ > > Key: GROOVY-7869 > URL: https://issues.apache.org/jira/browse/GROOVY-7869 > Project: Groovy > Issue Type: Bug > Components: groovy-runtime > Affects Versions: 2.4.0, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.4.5, 2.4.6, 2.4.7 > Environment: OS X/Linux/Windows > Reporter: Stanislav Poslavsky > > If one has a simple abstract iterable class and want to overload *plus* > operator using category, Groovy will use different implementation of 'plus' > from that defined in the category. > Abstract iterable class: > {code:java} > import java.util.Iterator; > public abstract class MyAbstractClass implements Iterable<Number> { > public final int num; > public MyAbstractClass(int num) { this.num = num; } > @Override > public String toString() { return String.valueOf(num); } > @Override > public Iterator<Number> iterator() { > //just some dummy empty iterator > return new Iterator<Number>() { > @Override > public boolean hasNext() { return false; } > @Override > public Number next() { return null; } > }; > } > } > {code} > A single implementation: > {code:java} > public class MyAbstractClassImpl extends MyAbstractClass { > public MyAbstractClassImpl(int a) { super(a); } > } > {code} > Category that overloads *plus* operator: > {code:java} > class MyCategory { > public static MyAbstractClass plus(MyAbstractClass a, MyAbstractClass b) { > return new MyAbstractClassImpl(a.num + b.num); > } > } > {code} > Test case: > {code:java} > use(MyCategory) { > def a = new MyAbstractClassImpl(1) > def b = new MyAbstractClassImpl(2) > println a + b //expected 3, but received [] > assert (a+b).num == 3 // so here we see exception > } > {code} > Expected to see *3*, but instead Groovy returns empty list, since it uses > plus operator defined for iterable, but not that is defined in MyCategory. > There is no bug in version 2.2.x. -- This message was sent by Atlassian JIRA (v6.3.4#6332)