Flyweight

1,029 views

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,029
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Flyweight

  1. 1. Flyweight 2011/4/252011 4 25
  2. 2. Flyweght =2011 4 25
  3. 3. 2011 4 25
  4. 4. 2011 4 25
  5. 5. Flyweight new2011 4 25
  6. 6. Flyweight ( )2011 4 25
  7. 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. 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. 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. 10. Flyweight (Immutable) java.lang.Integer java.math.BigDecimal2011 4 25
  11. 11. Enum2011 4 25
  12. 12. 2011 4 25
  13. 13. 2011 4 25
  14. 14. • Flywight • http://www.hyuki.com/dp/ cat_Flyweight.html2011 4 25

×