How to Generate Unique ID in Java (Integer)?

后端 未结 9 1501
生来不讨喜
生来不讨喜 2020-12-06 04:11

How to generate unique ID that is integer in java that not guess next number?

9条回答
  •  执念已碎
    2020-12-06 05:14

    If you really meant integer rather than int:

    Integer id = new Integer(42); // will not == any other Integer
    

    If you want something visible outside a JVM to other processes or to the user, persistent, or a host of other considerations, then there are other approaches, but without context you are probably better off using using the built-in uniqueness of object identity within your system.

提交回复
热议问题