随笔分类 - Code learing
记录值得学习的代码
-
对象比较中equals 与 ”==“的差别
摘要:要点:1、String str1 = "1";与 String str2 = new String("1"); 在内存中的表现是不同的。2、str2 = str2.intern();可以消除这种(str1、str2)不同。3、"==" 表示引用对象的引用比较,或则值对象的值比较。虽然String是引用对象,但是String的比较不能单纯的通过"=="实现,因为如 "1、"。4、Integer intObj = 1;Integer intObj2 = 1;int intNative = 1;的eq 阅读全文
-
抽象类的抽象方法及使用
摘要:class:java.util.AbstractMapline:381public abstract class AbstractMap<K,V> implements Map<K,V> { * Sole constructor. (For invocation by subclass constructors, typically protected AbstractMap() { ... * {@inheritDoc} public Collection<V> values() { if (values == null) { valu... 阅读全文
-
嵌套类引用实例化的外部类的方法
摘要:class:java.util.HashMapline:814HashMap.this.removeEntryForKey(k) 1 public class HashMap<K,V> 2 extends AbstractMap<K,V> 3 implements Map<K,V>, Cloneable, Serializable 4 { 5 ... 6 final Entry<K,V> removeEntryForKey(Object key) {...} 7 private abstract class HashIterator<E&g 阅读全文
-
可叠加定义的成员变量的赋值及操作(权限)
摘要:/** * The int value representing the public * modifier. */ public static final int PUBLIC = 0x00000001; /** * The int value representing the private * modifier. */ public static final int PRIVATE = 0x00000002; 阅读全文
-
static method and instance
摘要:java.beans.EventHandler.EventHandler public static T create(Class listenerInterface, Object target, String action, String eventPropertyName, String listenerMethodName){...} 阅读全文
-
Adapter
摘要:java.awt.event.MouseAdapter 阅读全文
-
最匹配
摘要:CLASS: java.beans.ReflectionUtilsMETHOD: getMostSpecificMethod(List, Class[]); 阅读全文
-
ForceInstance 与 non-ForceInstance
摘要:private List<Connection> cloneConnectionsForceInstance() { List<Connection> newList = new ArrayList<Connection>(); if (connections != null) newList.addAll(connections); return newList;}private List<Connection> cloneConnections() { if (connections == null) return null; List< 阅读全文
-
Java中List中remove的实质
摘要:A.如果List的泛型类型为引用类型(Object), 那么,remove只针对List实例所在的栈数据,堆数据的移除不由remove完成(是gc完成)。 B.List移除功能的核心,在Java内部的实现为: /* * Private remove method that skips bounds checking and does not * return the value removed. */ private void fastRemove(int index) { modCount++; int numMoved = size - index - 1; if (numMoved &g 阅读全文
-
数据处理的原子性(clone数据副本,再对数据副本做处理)
摘要:private synchronized void addConnection(Object receiver, Method slot,int connectionType) { ... ... List<Connection> newList = cloneConnectionsForceInstance(); newList.add(new Connection(receiver, slot, returnSig,(byte) connectionType)); connecti... 阅读全文