aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/java/lang/Byte.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/java/lang/Byte.java')
-rw-r--r--libjava/classpath/java/lang/Byte.java32
1 files changed, 31 insertions, 1 deletions
diff --git a/libjava/classpath/java/lang/Byte.java b/libjava/classpath/java/lang/Byte.java
index 338e2167aa1..2560bfcffc3 100644
--- a/libjava/classpath/java/lang/Byte.java
+++ b/libjava/classpath/java/lang/Byte.java
@@ -50,7 +50,7 @@ package java.lang;
* @author Per Bothner
* @author Eric Blake (ebb9@email.byu.edu)
* @since 1.1
- * @status updated to 1.4
+ * @status updated to 1.5
*/
public final class Byte extends Number implements Comparable
{
@@ -78,6 +78,16 @@ public final class Byte extends Number implements Comparable
public static final Class TYPE = VMClassLoader.getPrimitiveClass('B');
/**
+ * The number of bits needed to represent a <code>byte</code>.
+ * @since 1.5
+ */
+ public static final int SIZE = 8;
+
+ // This caches Byte values, and is used by boxing conversions via
+ // valueOf(). We're required to cache all possible values here.
+ private static Byte[] byteCache = new Byte[MAX_VALUE - MIN_VALUE + 1];
+
+ /**
* The immutable value of this Byte.
*
* @serial the wrapped byte
@@ -192,6 +202,26 @@ public final class Byte extends Number implements Comparable
}
/**
+ * Returns a <code>Byte</code> object wrapping the value.
+ * In contrast to the <code>Byte</code> constructor, this method
+ * will cache some values. It is used by boxing conversion.
+ *
+ * @param val the value to wrap
+ * @return the <code>Byte</code>
+ *
+ * @since 1.5
+ */
+ public static Byte valueOf(byte val)
+ {
+ synchronized (byteCache)
+ {
+ if (byteCache[val - MIN_VALUE] == null)
+ byteCache[val - MIN_VALUE] = new Byte(val);
+ return byteCache[val - MIN_VALUE];
+ }
+ }
+
+ /**
* Convert the specified <code>String</code> into a <code>Byte</code>.
* The <code>String</code> may represent decimal, hexadecimal, or
* octal numbers.