Reputation: 33
I'm shortening my UUID into a four digit number using the following code:
import java.nio.ByteBuffer;
import java.util.UUID;
/**
* Generate short UUID (13 characters)
*
* @return short UUID
*/
public class UUIDshortener
{
public static String shortUUID()
{
UUID uuid = UUID.randomUUID();
//long l = ByteBuffer.wrap(uuid.toString().getBytes()).getLong();
//return Long.toString(l, Character.MAX_RADIX);
return uuid.toString().hashCode();
}
}
I am getting the following error:
If anyone knows how to fix this it would be much appreciated. Is it as simple as changing it to an int?
Upvotes: 0
Views: 622
Reputation: 10945
Your method signature says you will return a String
public static String shortUUID()
but you are actually returning an int
, since that's the return type of the hashCode()
method
return uuid.toString().hashCode();
Just change your method sig to:
public static int shortUUID()
EDIT - to answer comment
There is no getInt()
method on the UUID
class, so uuid.getInt().hashCode()
won't compile. If you want to simplify your return statement, you can just hashCode()
directly on uuid like this:
return uuid.hashCode();
Upvotes: 1