Object类型编译基本类型


byte&short&int

1
2
3
4
5
6
7
Object a = 1;
 
// 字节码
0 iconst_1
1 invokestatic #2 <java/lang/Integer.valueOf>
4 astore_1
5 return

  

1
2
3
4
5
6
7
Object a = 127;
 
// 字节码
0 bipush 127
2 invokestatic #2 <java/lang/Integer.valueOf>
5 astore_1
6 return

  

1
2
3
4
5
6
7
Object a = 128;
 
// 字节码
0 sipush 128
3 invokestatic #2 <java/lang/Integer.valueOf>
6 astore_1
7 return

  

1
2
3
4
5
6
7
Object a = 2147483647;
 
// 字节码
0 ldc #2 <2147483647>
2 invokestatic #3 <java/lang/Integer.valueOf>
5 astore_1
6 return

  

Integer.valueOf()

  

1
2
3
4
5
public static Integer valueOf(int i) {
    if (i >= IntegerCache.low && i <= IntegerCache.high)
        return IntegerCache.cache[i + (-IntegerCache.low)];
    return new Integer(i);
}

  

long

 

1
2
3
4
5
6
7
Object a = 21474836478L;
 
// 字节码
0 ldc2_w #2 <21474836478>
3 invokestatic #4 <java/lang/Long.valueOf>
6 astore_1
7 return

  

Long.valueOf()

1
2
3
4
5
6
7
public static Long valueOf(long l) {
        final int offset = 128;
        if (l >= -128 && l <= 127) { // will cache
            return LongCache.cache[(int)l + offset];
        }
        return new Long(l);
    }

  

float&double

1
2
3
4
5
6
7
Object a = 3.4;
 
// 字节码
0 ldc2_w #2 <3.4>
3 invokestatic #4 <java/lang/Double.valueOf>
6 astore_1
7 return

  

1
2
3
4
5
6
7
Object a = 3.423;
 
// 字节码
0 ldc2_w #2 <3.423>
3 invokestatic #4 <java/lang/Double.valueOf>
6 astore_1
7 return

  

Double.valueOf

1
2
3
public static Double valueOf(double d) {
        return new Double(d);
    }

  

char

1
2
3
4
5
6
7
Object a = 'f';
 
// 字节码
0 bipush 102
2 invokestatic #2 <java/lang/Character.valueOf>
5 astore_1
6 return

  

Character.valueOf

1
2
3
4
5
6
public static Character valueOf(char c) {
        if (c <= 127) { // must cache
            return CharacterCache.cache[(int)c];
        }
        return new Character(c);
    }

  

boolean

1
2
3
4
5
6
7
Object a = false;
 
// 字节码
0 iconst_0
1 invokestatic #2 <java/lang/Boolean.valueOf>
4 astore_1
5 return

  

Boolean.valueOf

1
2
3
4
5
6
7
8
public static Boolean valueOf(String s) {
        return parseBoolean(s) ? TRUE : FALSE;
    }
 
 
public static boolean parseBoolean(String s) {
        return ((s != null) && s.equalsIgnoreCase("true"));
    }

  

  

posted on   anpeiyong  阅读(2)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-08-28 SQL---表内容查询
2020-08-28 SQL---修改表

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示