RFR(s): 8203670: unmodifiable List iterator() implementations should not be ListIterators
Zheka Kozlov
orionllmain at gmail.com
Tue Jun 26 06:11:36 UTC 2018
I agree with Ivan. Isn't it better to create a standalone implementation of
Iterator and return its instance in iterator()? Implementing of Iterator
for ImmutableList doesn't look like a big problem.
2018-06-26 6:14 GMT+07:00 Ivan Gerasimov <ivan.gerasimov at oracle.com>:
> Hi Stuart!
>
> Out of curiosity. What if someone does something like
>
> if (it instanceof ListIterator) {
> // optimized for bidirectional access
> } else {
> // slower algorithm
> }
>
> previous(), nextIndex() and previousIndex() methods are not declared to be
> optional, so is it appropriate to throw UnsupportedOperationException from
> them?
>
> Someone may assume that if an object can be cast to ListIterator
> interface, non-optional methods should not throw UOE.
>
> With kind regards,
>
> Ivan
>
>
>
> On 6/25/18 3:06 PM, Stuart Marks wrote:
>
>> Hi all,
>>
>> Please review this small changeset that ensures that calling iterator()
>> on an unmodifiable List (from List.of, et. al.) returns an instance that
>> cannot be downcast to ListIterator and used as such.
>>
>> Bug:
>>
>> https://bugs.openjdk.java.net/browse/JDK-8203670
>>
>> Webrev:
>>
>> http://cr.openjdk.java.net/~smarks/reviews/8203670/webrev.0/
>>
>> Thanks,
>>
>> s'marks
>>
>>
> --
> With kind regards,
> Ivan Gerasimov
>
>
More information about the core-libs-dev
mailing list