Vote count:
0
I have the following example code
public String getAliasSQL() {
StringBuilder builder = new StringBuilder();
if (field.getAlias().isPresent()) {
builder.append(" AS ");
builder.append(field.getAlias().get());
}
return builder.toString();
}
@Override
public Optional<String> getAlias() {
return field.getAlias();
}
And I am wondering if it is possible to do this with a one line statement using the guava or() method or another simple trick.
Something like
public String getAliasSQL() {
return field.getAlias().or("").prefixIfNotEmpty(" AS ");
}
But in a more readable way so it still would be clean code.
asked 25 secs ago
Guava optional of String or with prefix
Aucun commentaire:
Enregistrer un commentaire