Better use of generics to enforce types for serialization
This commit is contained in:
parent
06aeb876eb
commit
0f466ec40e
|
@ -38,7 +38,7 @@ interface SerializationManager {
|
|||
* Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when using this
|
||||
* method. The order must be the same at deserialization as it was for serialization.
|
||||
*/
|
||||
SerializationManager register(Class<?> clazz);
|
||||
<T> SerializationManager register(Class<T> clazz);
|
||||
|
||||
/**
|
||||
* Registers the class using the specified ID. If the ID is already in use by the same type, the old entry is overwritten. If the ID
|
||||
|
@ -51,7 +51,7 @@ interface SerializationManager {
|
|||
* @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and String, but
|
||||
* these IDs can be repurposed.
|
||||
*/
|
||||
SerializationManager register(Class<?> clazz, int id);
|
||||
<T> SerializationManager register(Class<T> clazz, int id);
|
||||
|
||||
/**
|
||||
* Registers the class using the lowest, next available integer ID and the specified serializer. If the class is already registered,
|
||||
|
@ -62,7 +62,7 @@ interface SerializationManager {
|
|||
* Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when using this
|
||||
* method. The order must be the same at deserialization as it was for serialization.
|
||||
*/
|
||||
SerializationManager register(Class<?> clazz, Serializer<?> serializer);
|
||||
<T> SerializationManager register(Class<T> clazz, Serializer<T> serializer);
|
||||
|
||||
/**
|
||||
* Registers the class using the specified ID and serializer. If the ID is already in use by the same type, the old entry is
|
||||
|
@ -75,7 +75,7 @@ interface SerializationManager {
|
|||
* @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and String, but
|
||||
* these IDs can be repurposed.
|
||||
*/
|
||||
SerializationManager register(Class<?> clazz, Serializer<?> serializer, int id);
|
||||
<T> SerializationManager register(Class<T> clazz, Serializer<T> serializer, int id);
|
||||
|
||||
/**
|
||||
* Waits until a kryo is available to write, using CAS operations to prevent having to synchronize.
|
||||
|
|
|
@ -36,28 +36,28 @@ class DefaultStorageSerializationManager implements SerializationManager {
|
|||
|
||||
@Override
|
||||
public
|
||||
SerializationManager register(final Class<?> clazz) {
|
||||
<T> SerializationManager register(final Class<T> clazz) {
|
||||
kryo.register(clazz);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public
|
||||
SerializationManager register(final Class<?> clazz, final int id) {
|
||||
<T> SerializationManager register(final Class<T> clazz, final int id) {
|
||||
kryo.register(clazz, id);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public
|
||||
SerializationManager register(final Class<?> clazz, final Serializer<?> serializer) {
|
||||
<T> SerializationManager register(final Class<T> clazz, final Serializer<T> serializer) {
|
||||
kryo.register(clazz, serializer);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public
|
||||
SerializationManager register(final Class<?> type, final Serializer<?> serializer, final int id) {
|
||||
<T> SerializationManager register(final Class<T> type, final Serializer<T> serializer, final int id) {
|
||||
kryo.register(type, serializer, id);
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user