Byte类型的SIZE是8,开始还以为是1呢。这个值是指使用的bit位数,而不是对象占内存大小。
Byte为有符号数,-128~127,初始化是初始值不能超过表示的范围,会抛异常,而不象C++会截断。
使用字符串类型初始化时,字符串不能为null或者"",否则会抛数字格式化异常。
结果:
=================== java.lang.Byte's information ===================
package name : java.lang
class name : java.lang.Byte
super class name : java.lang.Number
include method :
hashCode( )
compareTo( java.lang.Byte )
compareTo( java.lang.Object )
equals( java.lang.Object )
toString( byte )
toString( )
decode( java.lang.String )
valueOf( byte )
valueOf( java.lang.String int )
valueOf( java.lang.String )
byteValue( )
doubleValue( )
floatValue( )
intValue( )
longValue( )
shortValue( )
parseByte( java.lang.String )
parseByte( java.lang.String int )
wait( )
wait( long int )
wait( long )
getClass( )
notify( )
notifyAll( )
include field :
MIN_VALUE
MAX_VALUE
TYPE
SIZE
include Constructor :
java.lang.Byte( byte )
java.lang.Byte( java.lang.String )
Test Show:
Byte("123") = 123
Byte("-123") = -123
Byte("abc") = new Byte("abc") throw a NumberFormatException!
Byte((byte) (123)) = 123
Byte(null) = new Byte(null) throw a NumberFormatException!
Byte("") = new Byte(null) throw a NumberFormatException!
Byte.valueOf(null) = new Byte(null) throw a NumberFormatException!
Byte.parseByte("7b", 16) = 123
Byte.parseByte("-7b", 16) = -123
Byte.valueOf("7b", 16) = 123
Byte.valueOf("-7b", 16) = -123
Byte.TYPE = byte
Byte.SIZE = 8
Byte.MAX_VALUE = 127
Byte.MAX_VALUE+1 = -128
Byte.MIN_VALUE = -128
Byte.MIN_VALUE-1 = 127