JavaPoet Cheatsheet

Last modified: March 1, 2023


$L - literal value with no escaping.
$N emits a name, using name collision avoidance where necessary
addStatement("$N.toString()", fieldName)
// output
$S escapes the value as a string
addStatement("String initialValue = $S", initialValue)
// output
String initialValue = "EXCHANGE_RATE";
$T emits a type reference
addStatement("$T a = $S", String.class, "")
// output
String a = "";
$$ emits a dollar ($) sign

Control flow