map.values is an Object[] because this is in most cases faster than
creating a typed array using reflection (and this is what would have
to happen if you passed a concrete type). Also, map.values is exposed
publicly but is a rather internal detail which you should use only if
striving for maximum performance (or if you don't want to reallocate
by a call to toArray(java.lang.Class<? super KType> clazz)).
Finally, this is kind of explained in the JavaDoc of this field --
http://labs.carrotsearch.com/download/hppc/0.4.1/api/com/carrotsearch/hppc/ObjectArrayList.html#buffer
Hope this helps,
Dawid
Right, I understand reasoning for this.
> publicly but is a rather internal detail which you should use only if
> striving for maximum performance (or if you don't want to reallocate
> by a call to toArray(java.lang.Class<? super KType> clazz)).
Yes, in this case I do want maximum iteration speed, to go over
relatively large aggregated dataset.
In other cases I do create result array as it is more convenient.
> Finally, this is kind of explained in the JavaDoc of this field --
> http://labs.carrotsearch.com/download/hppc/0.4.1/api/com/carrotsearch/hppc/ObjectArrayList.html#buffer
Ah ok. I did miss that.
I will add casts as necessary and it'll work; just wanted to ping to
see if this is a known issue/caveat, and sounds like it is.
Thank you for quick answer!
-+ Tatu +-
You may want to try with pseudo-closures; if your code isn't too
complex they inline very well and provide excellent performance and
maybe a little bit cleaner code (depending on a particular use case
results may vary :).
> I will add casts as necessary and it'll work; just wanted to ping to
> see if this is a known issue/caveat, and sounds like it is.
Sure, thanks. I agree it is clumsy but out of several options that
I've tried (including actual typing of that array, generic Object[]
signature and explicit casts, etc.) this turned out to be least
annoying.
Dawid
Ok, I'll try that -- I did see a reference but for some reason went
with direct access.
One nice thing would be elimination of having to check the status flag.
>> I will add casts as necessary and it'll work; just wanted to ping to
>> see if this is a known issue/caveat, and sounds like it is.
>
> Sure, thanks. I agree it is clumsy but out of several options that
> I've tried (including actual typing of that array, generic Object[]
> signature and explicit casts, etc.) this turned out to be least
> annoying.
Yeah I know, generics are a PITA often, and I had to deal with
complexities of array allocation (for Jackson/JSON). While type-safety
of arrays is sometimes nice (compared to type-erased fakeness of
generics collections), it can also be a problem.
-+ Tatu +-