package com.hzp.CZX;
/**
* 测试拆装箱
* @author 夜孤寒
* @version 1.1.1
*/
public class TestDemo {
/**
* 拆装箱JDK1.5后
*/
public static void first(){
Integer i=7;//基本类型-->引用类型
int j=i;//引用类型-->基本类型
System.out.println(j);
}
/**
* 拆装箱JDK1.4
*/
public static void second(){
Integer i=new Integer(78);
int j=i.intValue();
System.out.println(j);
}
/**
* 测试方法
* @param args
*/
public static void main(String[] args) {
first();
second();
}
}
package com.ygh.CZX;
/**
* 关于java的拆装箱范围剖析
* @author 夜孤寒
* @version 1.1.1
*/
public class Test {
/**
* 以Integer类型为例
*/
public static void first(){
Integer i=new Integer(124);
Integer j=new Integer(124);
System.out.println(i==j);//false
Integer a1=-128;
Integer a2=-128;
System.out.println(a1==a2);//true
Integer b1=-129;
Integer b2=-129;
System.out.println(b1==b2);//false
Integer c1=127;
Integer c2=127;
System.out.println(c1==c2);//true
Integer d1=128;
Integer d2=128;
System.out.println(d1==d2);//false
}
public static void main(String[] args) {
first();
}
}
/**
* Returns an {@code Integer} instance representing the specified
* {@code int} value. If a new {@code Integer} instance is not
* required, this method should generally be used in preference to
* the constructor {@link #Integer(int)}, as this method is likely
* to yield significantly better space and time performance by
* caching frequently requested values.
*
* This method will always cache values in the range -128 to 127,
* inclusive, and may cache other values outside of this range.
*
* @param i an {@code int} value.
* @return an {@code Integer} instance representing {@code i}.
* @since 1.5
*/
public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
private static class IntegerCache {
static final int low = -128;
static final int high;
static final Integer cache[];
static {
// high value may be configured by property
int h = 127;
String integerCacheHighPropValue =
sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
if (integerCacheHighPropValue != null) {
try {
int i = parseInt(integerCacheHighPropValue);
i = Math.max(i, 127);
// Maximum array size is Integer.MAX_VALUE
h = Math.min(i, Integer.MAX_VALUE - (-low) -1);
} catch( NumberFormatException nfe) {
// If the property cannot be parsed into an int, ignore it.
}
}
high = h;
cache = new Integer[(high - low) + 1];
int j = low;
for(int k = 0; k < cache.length; k++)
cache[k] = new Integer(j++);
// range [-128, 127] must be interned (JLS7 5.1.7)
assert IntegerCache.high >= 127;
}
private IntegerCache() {}
}
package com.ygh.CZX;
/**
* 关于java的拆装箱范围剖析
*
* @author 夜孤寒
* @version 1.1.1
*/
public class Test {
/**
* Double
*/
public static void first() {
Double i1 = 100.0;
Double i2 = 100.0;
Double i3 = 200.0;
Double i4 = 200.0;
System.out.println(i1 == i2);//false
System.out.println(i3 == i4);//false
}
/**
* 测试方法
*/
public static void main(String[] args) {
first();
}
}
/**
* Returns a {@code Double} instance representing the specified
* {@code double} value.
* If a new {@code Double} instance is not required, this method
* should generally be used in preference to the constructor
* {@link #Double(double)}, as this method is likely to yield
* significantly better space and time performance by caching
* frequently requested values.
*
* @param d a double value.
* @return a {@code Double} instance representing {@code d}.
* @since 1.5
*/
public static Double valueOf(double d) {
return new Double(d);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有