2011-02-14 61 views

回答

2

如果你在运行时只需要唯一的ID,那么处理ID的单身就足够了。

public class UidUtils { 

    private UidUtils() {} 

    /** 
    * A unique identifier. 
    */ 
    private static int uid = 1; 

    /** 
    * Deliver the next uid. 
    * 
    * @return The next uid. 
    */ 
    public static int getNextUid() { 
     return ++uid; 
    } 

}