commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shevek (JIRA)" <>
Subject [jira] [Commented] (LANG-819) EnumUtils.generateBitVector needs a "? extends"
Date Fri, 10 Jan 2014 21:01:55 GMT


Shevek commented on LANG-819:

Thank you very much for the responses.

C++ can do "Foo const * const * const *" which tells you whether it's the pointer or the target
which is immutable. Java can basically only make the pointers immutable without a little help
from this trick. Yes, you _can_ mutate the collection with Iterator.remove() or Collection.clear()
but at least the programmer has already been forced to declare their knowledge that this is
Naughty(tm). Also, clear() is presumably slower than the garbage collector if the object is
still in eden space, so who does that anyway? Also, see all Google's typed-immutable collections,
which, in return for being immutable, save memory and improve performance.

Yes, I think that last Google case from Thomas can't _quite_ be expressed in the Java type
system - it's not actually quite complete and consistent. You get wrapped up in "? super (?
extends E)" which isn't sufficiently well defined in the lattice. Some of us would love to
reduce that to "? super E" which would suffice for practical purposes, but isn't mathematically
correct. Don't take this comment as gospel - check yourself. I don't tend to use transform()
or map-reduce structures as much as I used to because I tend to be working with very large
implicit collections where C*'s OpenBitSet is more relevant than java.util.BitSet or generateBitVector().

> EnumUtils.generateBitVector needs a "? extends"
> -----------------------------------------------
>                 Key: LANG-819
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.0.1
>            Reporter: Shevek
>            Priority: Minor
>             Fix For: 3.3
>     public static <E extends Enum<E>> long generateBitVector(Class<E>
enumClass, Iterable<E> values) {
> Should be Iterable<? extends E>.
> This is because although no subclasses of E can exist, the "? extends" is a common idiom
for marking the collection as readonly, or not "owned" by the current object.

This message was sent by Atlassian JIRA

View raw message