How can I create an empty java.util.UUID object?

Let me preface this by saying it would be much better to use Option[UUID] instead, with None representing an empty UUID.

You can't use an empty String, as it does not conform to the UUID format, described here.

You could use

UUID.fromString("00000000-0000-0000-0000-000000000000")

Which would be the same as

new UUID(0L, 0L)

But the usage of that would be arbitrary, and it would be much better to signify the absence or lack of a UUID with Option.


Did you consider using Option[UUID] as a parameter type? In this case you can pass None to indicate lack of UUID. An empty string is not a valid guid that's why it is rejected by UUID.fromString

Tags:

Java

Uuid

Scala