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

I don’t know why I cannot find the answer to this question, but I need to pass an empty UUID object in one of my functions in order to represent the absence of the UUID. What is a UUID-like form?

val x: "" 

which will be an empty string. I am essentially trying to get an empty UUID. I tried

 UUID.fromString("") 

but got an error since you need a valid UUID string.

EDIT: I implement this in Scala.

+6
source share
2 answers

Let me preface this by saying that I’m much better off using Option[UUID] and None represents an empty UUID.

You cannot use an empty String , since it does not conform to the UUID format described here .

you can use

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

It will be the same as

 new UUID(0L, 0L) 

But using this would be arbitrary, and it would be much better to indicate the absence or absence of UUID with Option .

+13
source

Do you consider using the [UUID] option as the parameter type? In this case, you can pass None to indicate the absence of a UUID. An empty string is not a valid director, so it is rejected using UUID.fromString

+9
source

Source: https://habr.com/ru/post/977429/


All Articles