From 3b3101d8b5ae4f08a16c0b7111da6cad41bbd282 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 15 Nov 2005 23:20:01 +0000 Subject: Imported GNU Classpath 0.19 + gcj-import-20051115. * sources.am: Regenerated. * Makefile.in: Likewise. * scripts/makemake.tcl: Use glob -nocomplain. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107049 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/classpath/java/lang/Byte.java | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'libjava/classpath/java/lang/Byte.java') 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 { @@ -77,6 +77,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 byte. + * @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. * @@ -192,6 +202,26 @@ public final class Byte extends Number implements Comparable } /** + * Returns a Byte object wrapping the value. + * In contrast to the Byte constructor, this method + * will cache some values. It is used by boxing conversion. + * + * @param val the value to wrap + * @return the Byte + * + * @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 String into a Byte. * The String may represent decimal, hexadecimal, or * octal numbers. -- cgit v1.2.3