Integer cache

it2022-05-09  59

View.findViewById采用深度遍历,找到第一个匹配的控件Integer Cache 1 public static void testIntegerCache() { 2 Class cache = Integer.class.getDeclaredClasses()[0]; 3 try { 4 Field f = cache.getDeclaredField("cache"); 5 f.setAccessible(true); 6 Integer[] array = (Integer[]) f.get(cache); 7 array[130] = array[131]; 8 } catch (Exception e) { 9 e.printStackTrace(); 10 } 11 System.out.printf("1+1=%d", 1+1); 12 } View Code 上面关键在于Integer.valueOf()方法 1 public static Integer valueOf(int i) { 2 if(i >= -128 && i <= IntegerCache.high) 3 return IntegerCache.cache[i + 128]; 4 else 5 return new Integer(i); 6 } View Code

 

 

转载于:https://www.cnblogs.com/maozhige/p/3767765.html


最新回复(0)