java 中一般用hashcode的InstanceID来实现,
hashcode为什么不适合你呢?不解

解决方案 »

  1.   

    在SQLSERVER2000中主键可以自动产生一个Guid,我想与之匹配!所以觉得用HASHCODE码不太适合!
      

  2.   

    在JAVA中如果需要使用HASHCODE,不是要先定义一个对象或者变量,以及来产生该对象或者变量的HASHCODE吗?
      

  3.   

    使用单例的一个例子!
    也有使用数据库的例子!public class Client
    {
        private static KeyGenerator keygen;    public static void main(String[] args)
        {
            keygen = KeyGenerator.getInstance();        System.out.println("key = " + keygen.getNextKey());
            System.out.println("key = " + keygen.getNextKey());
            System.out.println("key = " + keygen.getNextKey());
        }}public class KeyGenerator
    {
        private static KeyGenerator keygen =
        new KeyGenerator();    private int key = 1000;    private KeyGenerator() { }    public static KeyGenerator getInstance()
        {
            return keygen;
        }    public synchronized int getNextKey()
        {
            return key++;
        }
    }
      

  4.   

    而且在J2SE的类库当中KeyGenerator好像是采用密码的吧!