Elegant way to assign object id in Java

后端 未结 4 1614
感情败类
感情败类 2020-12-09 03:52

I have a class for objects ... lat\'s say apples.

Each apple object mush have a unique identifier (id)... how do I ensure (elegantly and efficiently) that newly crea

4条回答
  •  抹茶落季
    2020-12-09 04:51

    Have you thought about using UUID class. You can call the randomUUID() function to create a new id everytime.

提交回复
热议问题