提交 22d67ed5 编写于 作者: M mduigou

7088952: Add size in bytes constant "BYTES" to primitive type wrapper types

Summary: Adds a constant BYTES to each of the primitive wrapper classes (Byte, Character, Double, Float, Integer, Long, Short) with the calculation Primitive.SIZE / Byte.SIZE already made.
Reviewed-by: dholmes
上级 34b28a86
...@@ -507,6 +507,14 @@ public final class Byte extends Number implements Comparable<Byte> { ...@@ -507,6 +507,14 @@ public final class Byte extends Number implements Comparable<Byte> {
*/ */
public static final int SIZE = 8; public static final int SIZE = 8;
/**
* The number of bytes used to represent a {@code byte} value in two's
* complement binary form.
*
* @since 1.8
*/
public static final int BYTES = SIZE / Byte.SIZE;
/** use serialVersionUID from JDK 1.1. for interoperability */ /** use serialVersionUID from JDK 1.1. for interoperability */
private static final long serialVersionUID = -7183698231559129828L; private static final long serialVersionUID = -7183698231559129828L;
} }
...@@ -7170,6 +7170,14 @@ class Character implements java.io.Serializable, Comparable<Character> { ...@@ -7170,6 +7170,14 @@ class Character implements java.io.Serializable, Comparable<Character> {
*/ */
public static final int SIZE = 16; public static final int SIZE = 16;
/**
* The number of bytes used to represent a {@code char} value in unsigned
* binary form.
*
* @since 1.8
*/
public static final int BYTES = SIZE / Byte.SIZE;
/** /**
* Returns the value obtained by reversing the order of the bytes in the * Returns the value obtained by reversing the order of the bytes in the
* specified <tt>char</tt> value. * specified <tt>char</tt> value.
......
...@@ -122,6 +122,13 @@ public final class Double extends Number implements Comparable<Double> { ...@@ -122,6 +122,13 @@ public final class Double extends Number implements Comparable<Double> {
*/ */
public static final int SIZE = 64; public static final int SIZE = 64;
/**
* The number of bytes used to represent a {@code double} value.
*
* @since 1.8
*/
public static final int BYTES = SIZE / Byte.SIZE;
/** /**
* The {@code Class} instance representing the primitive type * The {@code Class} instance representing the primitive type
* {@code double}. * {@code double}.
......
...@@ -120,6 +120,13 @@ public final class Float extends Number implements Comparable<Float> { ...@@ -120,6 +120,13 @@ public final class Float extends Number implements Comparable<Float> {
*/ */
public static final int SIZE = 32; public static final int SIZE = 32;
/**
* The number of bytes used to represent a {@code float} value.
*
* @since 1.8
*/
public static final int BYTES = SIZE / Byte.SIZE;
/** /**
* The {@code Class} instance representing the primitive type * The {@code Class} instance representing the primitive type
* {@code float}. * {@code float}.
......
...@@ -1297,6 +1297,14 @@ public final class Integer extends Number implements Comparable<Integer> { ...@@ -1297,6 +1297,14 @@ public final class Integer extends Number implements Comparable<Integer> {
*/ */
public static final int SIZE = 32; public static final int SIZE = 32;
/**
* The number of bytes used to represent a {@code int} value in two's
* complement binary form.
*
* @since 1.8
*/
public static final int BYTES = SIZE / Byte.SIZE;
/** /**
* Returns an {@code int} value with at most a single one-bit, in the * Returns an {@code int} value with at most a single one-bit, in the
* position of the highest-order ("leftmost") one-bit in the specified * position of the highest-order ("leftmost") one-bit in the specified
......
...@@ -1319,6 +1319,14 @@ public final class Long extends Number implements Comparable<Long> { ...@@ -1319,6 +1319,14 @@ public final class Long extends Number implements Comparable<Long> {
*/ */
public static final int SIZE = 64; public static final int SIZE = 64;
/**
* The number of bytes used to represent a {@code long} value in two's
* complement binary form.
*
* @since 1.8
*/
public static final int BYTES = SIZE / Byte.SIZE;
/** /**
* Returns a {@code long} value with at most a single one-bit, in the * Returns a {@code long} value with at most a single one-bit, in the
* position of the highest-order ("leftmost") one-bit in the specified * position of the highest-order ("leftmost") one-bit in the specified
......
...@@ -470,6 +470,14 @@ public final class Short extends Number implements Comparable<Short> { ...@@ -470,6 +470,14 @@ public final class Short extends Number implements Comparable<Short> {
*/ */
public static final int SIZE = 16; public static final int SIZE = 16;
/**
* The number of bytes used to represent a {@code short} value in two's
* complement binary form.
*
* @since 1.8
*/
public static final int BYTES = SIZE / Byte.SIZE;
/** /**
* Returns the value obtained by reversing the order of the bytes in the * Returns the value obtained by reversing the order of the bytes in the
* two's complement representation of the specified {@code short} value. * two's complement representation of the specified {@code short} value.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册