yangxu998 / guava-libraries

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

add bits(), bytes() to Primitives #672

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The Primitives class itself could use 
 static int bits(Class clazz)
 static int bytes(Class clazz)
which would throw on a class that isn't a JDK primitive wrapper.

FWIW, see 
http://stackoverflow.com/questions/6766343/best-practice-for-getting-datatype-si
zesizeof-in-java/6772163#6772163 for what motivated me to write.

Original issue reported on code.google.com by fry@google.com on 28 Jul 2011 at 5:30

GoogleCodeExporter commented 9 years ago
(Reported by estaub2).

I would consider Primitives.bytes() but leave the *8 to the caller for bits.

The question is who would use it and why?

Original comment by kevinb@google.com on 28 Jul 2011 at 8:35

GoogleCodeExporter commented 9 years ago
>> who would use it and why?

It might be used by anyone who needs to rapidly hard-allocate space for 
primitives and needs to do it in a generic way - possibly driven by reflection, 
for instance.  While nio makes this less frequently needed, with 
Byte/Char/...*Buffer, et al, it's still sometimes necessary - for instance, 
when byte-ordering is important.  It's possible that this kind of low-level 
code is either too rare or outside the Guava "sweet spot" - it was just a 
thought!

If it does seem worth doing, I'd extend the original suggestion to handle the 
"dummy" classes returned by reflection for unwrapped primitives, as well as the 
wrappers - both "long.class" and "Long.class".

Original comment by esta...@comcast.net on 28 Jul 2011 at 11:02

GoogleCodeExporter commented 9 years ago

Original comment by fry@google.com on 10 Dec 2011 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by fry@google.com on 16 Feb 2012 at 7:17

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 30 May 2012 at 7:43

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 22 Jun 2012 at 6:16

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 1 Nov 2014 at 4:18

GoogleCodeExporter commented 9 years ago

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