T - The type of wrapped value. Should be an immutable value-type.public abstract class JustA<T> extends Object implements Serializable
extends JustA<SomeType> decalaration in your class definition.
A common pattern for using this class would be:
interface WithName {
static JustAName of(String name) {
return new JustAName(name);
}
final class JustAName extends JustA<String> implements WithName {
private JustAName(String name) {
super(name);
}
public String getName() {
return theValue;
}
}
String getName();
}
This yields certain benefits, as you now have an interface (WithName) to use with your
more complex domain types, which among other stuff, having a name. And you have a neat way to pass
typed simple values using WithName.of("John Doe"). This especially enhances the readability of
method invocations with multiple arguments, as you must explicitly state the semantics of each argument.
Say a query of some sort:
db.findPerson(WithName.of("John Doe"), WithPhonenumber.of("555-98437"))
If the method parameters for some reason are refactored to switch places, the code invoking the method will not compile
anymore, as the arguments are not given in the correct order even though they are really just Strings.
| Modifier | Constructor and Description |
|---|---|
protected |
JustA(T theValue) |
protected |
JustA(T theValue,
SerializableFunction<? super T,String> valueToString) |
protected |
JustA(T theValue,
String description) |
protected |
JustA(T theValue,
String description,
SerializableFunction<? super T,String> valueToString) |
Copyright © 2018 Digipost. All rights reserved.