T - The type of wrapped value. Should be an immutable value-type.public abstract class JustALong extends Object implements Serializable
long" value classes, for cases
when you do not want to pass around simple longs for numbers that has
certain (business-) semantics in your application, even though a long
does adequately express the value. By extending this class you do not have to
implement the equals and hashcode. You would not refer to this class
other than with an extends JustALong decalaration in your class definition.
This is a special case implementation of JustA to avoid the boxing cost
for primitive longs. The typical use for this are for ids, and classes
where instances are uniquely distinguished by their long ids, and equals/hashcode
will exercise correct behavior when only operating on the id. Any additional
fields in an extending class should usually be declared final.
A common pattern for using this class would be:
interface WithId {
static JustAnId of(long id) {
return new JustAnId(id);
}
final class JustAnId extends JustALong implements WithId {
private JustAnId(String id) {
super(id);
}
public long getId() {
return theValue;
}
}
long getId();
}| Modifier and Type | Field and Description |
|---|---|
protected long |
theLong |
| Modifier | Constructor and Description |
|---|---|
protected |
JustALong(long theValue) |
protected |
JustALong(long theValue,
SerializableFunction<? super Long,String> valueToString) |
protected |
JustALong(long theValue,
String description) |
protected |
JustALong(long theValue,
String description,
SerializableFunction<? super Long,String> valueToString) |
protected JustALong(long theValue)
protected JustALong(long theValue,
String description)
protected JustALong(long theValue,
SerializableFunction<? super Long,String> valueToString)
protected JustALong(long theValue,
String description,
SerializableFunction<? super Long,String> valueToString)
Copyright © 2018 Digipost. All rights reserved.