mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-25 02:06:05 +02:00
java: NilType::create() returns NilType's one and only instance
This commit is contained in:
@@ -23,7 +23,7 @@ import java.util.Map;
|
|||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
public abstract class MessagePackObject implements Cloneable, MessagePackable {
|
public abstract class MessagePackObject implements Cloneable, MessagePackable {
|
||||||
public boolean isNull() {
|
public boolean isNil() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,16 @@ import java.io.IOException;
|
|||||||
import org.msgpack.*;
|
import org.msgpack.*;
|
||||||
|
|
||||||
public class NilType extends MessagePackObject {
|
public class NilType extends MessagePackObject {
|
||||||
private static NilType instance = new NilType();
|
private final static NilType INSTANCE = new NilType();
|
||||||
|
|
||||||
public static NilType create() {
|
public static NilType create() {
|
||||||
return instance;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NilType() { }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNull() {
|
public boolean isNil() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ public class NilType extends MessagePackObject {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new NilType();
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public class TestPackUnpack {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
new Packer(out).packNil();
|
new Packer(out).packNil();
|
||||||
MessagePackObject obj = unpackOne(out);
|
MessagePackObject obj = unpackOne(out);
|
||||||
assertTrue(obj.isNull());
|
assertTrue(obj.isNil());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user