More Related Content
More from Hiroyuki Ohnaka
More from Hiroyuki Ohnaka (20)
Flyweight
- 7. @Test
public void Integer () throws Exception {
Integer integer1_first = Integer.valueOf(1);
Integer integer2 = Integer.valueOf(2);
Integer integer1_second = Integer.valueOf(1);
Integer integer1_third = new Integer(1);
//
assertTrue(integer1_first == integer1_second);
//
assertFalse(integer1_first == integer2);
//
assertFalse(integer1_first == integer1_third);
}
2011 4 25
- 8. public static Integer valueOf(int i) {
assert IntegerCache.high >= 127;
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-
IntegerCache.low)];
return new Integer(i);
}
2011 4 25
- 9. ...
@Test
public void Integer () throws Exception {
Integer integer127_first = 127;
Integer integer127_second = 127;
assertTrue(integer127_first == integer127_second);
Integer integer128_first = 128;
Integer integer128_second = 128;
//
assertFalse(integer128_first == integer128_second);
}
2011 4 25
- 10. Flyweight
(Immutable)
java.lang.Integer
java.math.BigDecimal
2011 4 25
- 14. • Flywight
• http://www.hyuki.com/dp/
cat_Flyweight.html
2011 4 25