Expose elementType of EnumSet and EnumMap
mwisnicki at gmail.com
Sun Sep 22 14:05:08 UTC 2013
On Sun, Sep 22, 2013 at 11:17 AM, Remi Forax <forax at univ-mlv.fr> wrote:
> There is a lot of code that cast to T or to EnumSet<T> that will start to fail at runtime if generics are reified.
Yes, but how is that relevant ? Most of the code using reflection or
unchecked casts will likely fail if existing generics get reified
which is why IMHO it won't be added, at least not to existing classes.
> One possible way to avoid that is to create a new collection API, another is to try to reuse existing implementations with an opt-in mecanism. In the later case, the same class will be seen refiied
> or not depending on how the collection is created, so enabling reification will be done incrementally in that case.
> getElementType is a way to export a refied type, it will add burden to mixed mode implementation.
Whether EnumSet<T> is reified or not, it does not change the fact that
it is and must be associated with a class that declares enum values.
There can be only one such class in any case.
> You have to propagate declared types otherwise your code is not typesafe.
> If you don't propagate type that you can de-serialize a List of String without checking that the elements inside the List are String.
Indeed, such code is not safe, but almost all serialization APIs let
you read/write an object without specifying its type. That includes
java serialization, which is only safe in case of EnumSet due to
specific handling inside that class.
More information about the core-libs-dev