kucci / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Primitives toArray should take Collection<? extends Number> #443

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a use case where I'd like to perform primitive conversions on an array 
of values.  For example, from long[] to double[].  

Currently, the primitive classes, such as Longs have a helpful method toArray 
which takes a Collection of the given wrapper type and returns an array of the 
primitive type using unboxing.

If they instead took a Collection<? extends Number> and used the primitive 
accessors of Number directly (e.g. doubleValue()) then they could be combined 
to perform these conversions between any primitive types.

For example:
long[] inputValues = ...
double[] outputValues = Doubles.toArray(Longs.asList(inputValues));

Original issue reported on code.google.com by ddlat...@gmail.com on 6 Oct 2010 at 11:03

GoogleCodeExporter commented 9 years ago
Bumped into this case again in another place.  It should be a simple change to 
make.

Perhaps it's more difficult to evaluate?  Are there concerns about including it 
in the next guava release?

Original comment by ddlat...@gmail.com on 26 May 2011 at 7:55

GoogleCodeExporter commented 9 years ago
No, it evaluates identically, so your proposed change would be a correct one 
IMO.

Original comment by tv@duh.org on 26 May 2011 at 8:12

GoogleCodeExporter commented 9 years ago
As far as I understand it, this change should be both source- and 
binary-compatible. Can anyone think of negative consequences? Certainly it 
would cause a CCE if for whatever reason you end up running against an older 
version of Guava than you compiled against, but that is not a case I really 
want to worry about.

Original comment by kevinb@google.com on 18 Jul 2011 at 3:49

GoogleCodeExporter commented 9 years ago

Original comment by fry@google.com on 10 Dec 2011 at 3:50

GoogleCodeExporter commented 9 years ago
Possible 12.0ness here if we can validate the safety

Original comment by kevinb@google.com on 2 Mar 2012 at 8:09

GoogleCodeExporter commented 9 years ago
Looking into this...

Original comment by kak@google.com on 5 Mar 2012 at 8:38

GoogleCodeExporter commented 9 years ago
This'll go out w/ 12.0

Original comment by kak@google.com on 12 Mar 2012 at 10:07

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09