接口 PersistentDataType<T,Z>

类型参数:
T - the primary object type that is stored in the given tag
Z - the retrieved object type when applying this tag type
所有已知实现类:
PersistentDataType.BooleanPersistentDataType, PersistentDataType.PrimitivePersistentDataType

public interface PersistentDataType<T,Z>
This class represents an enum with a generic content type. It defines the types a custom tag can have.

This interface can be used to create your own custom PersistentDataType with different complex types. This may be useful for the likes of a UUIDTagType:

 
 public class UUIDTagType implements PersistentDataType<byte[], UUID> {

         {@literal @Override}
         public Class<byte[]> getPrimitiveType() {
             return byte[].class;
         }

         {@literal @Override}
         public Class<UUID> getComplexType() {
             return UUID.class;
         }

         {@literal @Override}
         public byte[] toPrimitive(UUID complex, PersistentDataAdapterContext context) {
             ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
             bb.putLong(complex.getMostSignificantBits());
             bb.putLong(complex.getLeastSignificantBits());
             return bb.array();
         }

         {@literal @Override}
         public UUID fromPrimitive(byte[] primitive, PersistentDataAdapterContext context) {
             ByteBuffer bb = ByteBuffer.wrap(primitive);
             long firstLong = bb.getLong();
             long secondLong = bb.getLong();
             return new UUID(firstLong, secondLong);
         }
     }