50 |
* @author Per Bothner |
* @author Per Bothner |
51 |
* @author Eric Blake (ebb9@email.byu.edu) |
* @author Eric Blake (ebb9@email.byu.edu) |
52 |
* @since 1.1 |
* @since 1.1 |
53 |
* @status updated to 1.4 |
* @status updated to 1.5 |
54 |
*/ |
*/ |
55 |
public final class Byte extends Number implements Comparable |
public final class Byte extends Number implements Comparable |
56 |
{ |
{ |
78 |
public static final Class TYPE = VMClassLoader.getPrimitiveClass('B'); |
public static final Class 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 |
* The immutable value of this Byte. |
* The immutable value of this Byte. |
92 |
* |
* |
93 |
* @serial the wrapped byte |
* @serial the wrapped byte |
202 |
} |
} |
203 |
|
|
204 |
/** |
/** |
205 |
|
* Returns a <code>Byte</code> object wrapping the value. |
206 |
|
* In contrast to the <code>Byte</code> constructor, this method |
207 |
|
* will cache some values. It is used by boxing conversion. |
208 |
|
* |
209 |
|
* @param val the value to wrap |
210 |
|
* @return the <code>Byte</code> |
211 |
|
* |
212 |
|
* @since 1.5 |
213 |
|
*/ |
214 |
|
public static Byte valueOf(byte val) |
215 |
|
{ |
216 |
|
synchronized (byteCache) |
217 |
|
{ |
218 |
|
if (byteCache[val - MIN_VALUE] == null) |
219 |
|
byteCache[val - MIN_VALUE] = new Byte(val); |
220 |
|
return byteCache[val - MIN_VALUE]; |
221 |
|
} |
222 |
|
} |
223 |
|
|
224 |
|
/** |
225 |
* Convert the specified <code>String</code> into a <code>Byte</code>. |
* Convert the specified <code>String</code> into a <code>Byte</code>. |
226 |
* The <code>String</code> may represent decimal, hexadecimal, or |
* The <code>String</code> may represent decimal, hexadecimal, or |
227 |
* octal numbers. |
* octal numbers. |