I don't know why I can't find the answer to this, but I need to pass a blank UUID object in one of my functions to represent a lack of UUID. What is the UUID analagous form of
val x: ""
, which would be an empty string. I'm essentially trying to get an empty UUID. I tried
UUID.fromString("")
but received an error, as you need a valid UUID string.
EDIT: I am implementing this in Scala.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.