1 |
/* Byte.java -- object wrapper for byte |
/* Byte.java -- object wrapper for byte |
2 |
Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. |
Copyright (C) 1998, 2001, 2002, 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
52 |
* @since 1.1 |
* @since 1.1 |
53 |
* @status updated to 1.4 |
* @status updated to 1.4 |
54 |
*/ |
*/ |
55 |
public final class Byte extends Number implements Comparable |
public final class Byte extends Number implements Comparable<Byte> |
56 |
{ |
{ |
57 |
/** |
/** |
58 |
* Compatible with JDK 1.1+. |
* Compatible with JDK 1.1+. |
75 |
* The primitive type <code>byte</code> is represented by this |
* The primitive type <code>byte</code> is represented by this |
76 |
* <code>Class</code> object. |
* <code>Class</code> object. |
77 |
*/ |
*/ |
78 |
public static final Class TYPE = VMClassLoader.getPrimitiveClass('B'); |
public static final Class<Byte> TYPE = VMClassLoader.getPrimitiveClass('B'); |
79 |
|
|
80 |
|
/** |
81 |
|
* The number of bits needed to represent a <code>byte</code>. |
82 |
|
* @since 1.5 |
83 |
|
*/ |
84 |
|
public static final int SIZE = 8; |
85 |
|
|
86 |
|
// This caches Byte values, and is used by boxing conversions via |
87 |
|
// valueOf(). We're required to cache all possible values here. |
88 |
|
private static Byte[] byteCache = new Byte[MAX_VALUE - MIN_VALUE + 1]; |
89 |
|
|
90 |
|
|
91 |
/** |
/** |
92 |
* The immutable value of this Byte. |
* The immutable value of this Byte. |
203 |
} |
} |
204 |
|
|
205 |
/** |
/** |
206 |
|
* Returns a <code>Byte</code> object wrapping the value. |
207 |
|
* In contrast to the <code>Byte</code> constructor, this method |
208 |
|
* will cache some values. It is used by boxing conversion. |
209 |
|
* |
210 |
|
* @param val the value to wrap |
211 |
|
* @return the <code>Byte</code> |
212 |
|
*/ |
213 |
|
public static Byte valueOf(byte val) |
214 |
|
{ |
215 |
|
synchronized (byteCache) |
216 |
|
{ |
217 |
|
if (byteCache[val - MIN_CACHE] == null) |
218 |
|
byteCache[val - MIN_CACHE] = new Byte(val); |
219 |
|
return byteCache[val - MIN_CACHE]; |
220 |
|
} |
221 |
|
} |
222 |
|
|
223 |
|
/** |
224 |
* Convert the specified <code>String</code> into a <code>Byte</code>. |
* Convert the specified <code>String</code> into a <code>Byte</code>. |
225 |
* The <code>String</code> may represent decimal, hexadecimal, or |
* The <code>String</code> may represent decimal, hexadecimal, or |
226 |
* octal numbers. |
* octal numbers. |