增加setIfNull方法
This commit is contained in:
@@ -20,22 +20,28 @@ public final class ObjectReference<V> {
|
|||||||
private V value;
|
private V value;
|
||||||
|
|
||||||
public ObjectReference(V initialValue) {
|
public ObjectReference(V initialValue) {
|
||||||
value = initialValue;
|
this.value = initialValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectReference() {
|
public ObjectReference() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final V get() {
|
public final V get() {
|
||||||
return value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void set(V newValue) {
|
public final void set(V newValue) {
|
||||||
value = newValue;
|
this.value = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setIfNull(V newValue) {
|
||||||
|
if (this.value == null) {
|
||||||
|
this.value = newValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.valueOf(value);
|
return String.valueOf(this.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user