You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Shil Sinha (JIRA)" <ji...@apache.org> on 2015/11/01 18:11:27 UTC
[jira] [Created] (GROOVY-7654) Iterable as List and
Iterable.asList() have different semantics
Shil Sinha created GROOVY-7654:
----------------------------------
Summary: Iterable as List and Iterable.asList() have different semantics
Key: GROOVY-7654
URL: https://issues.apache.org/jira/browse/GROOVY-7654
Project: Groovy
Issue Type: Bug
Components: groovy-jdk
Affects Versions: 2.4.5
Reporter: Shil Sinha
For an Iterable `foo` which is not also a collection, `foo.asList()` and `foo as List` are not equivalent. The latter goes through the asType(Object, Class) path and ultimately returns a proxy. This is unexpected, and can result in some inconsistencies. A simple example:
{code}
class IterableWrapper implements Iterable {
Iterable delegate
Iterator iterator() {
delegate.iterator()
}
}
def itw = new IterableWrapper(delegate: [1,2,3])
def itwAsList = itw.asList()
def itwAsTypeList = itw as List
assert itwAsList == itwAsTypeList
assert itwAsList[0] == itwAsTypeList[0]
{code}
The first assertion passes, but the second fails with:
{code}
groovy.lang.MissingMethodException: No signature of method: IterableWrapper.get() is applicable for argument types: (java.lang.Integer) values: [0]
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)