2011-02-14 49 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; 
    } 

} 
相關問題