Annotation Interface TemplateFormatMethod


@Documented @Target({METHOD,CONSTRUCTOR}) public @interface TemplateFormatMethod
Annotates a method that uses a template string and fills the "{placeholder}"s in the template with arguments. Such methods expect a string parameter annotated with @TemplateString.

For example with:

 @TemplateFormatMethod
 BillingException reportBillingError(@TemplateString String template, Object... args) {
   ...
 }
The method can be called like reportBillingError("id: {id}", id).

Similar to but different from ErrorProne's @FormatMethod, @TemplateFormatMethod methods use named placeholders instead of the printf style "%s". Such methods work better when the template strings are constants shared among multiple classes.

To minimize confusion, the template parameter must be annotated with @TemplateString. It's not optional.

Since:
8.0