@Target(allowedTargets = [AnnotationTarget.FUNCTIONAnnotationTarget.FIELDAnnotationTarget.CONSTRUCTOR])
public annotation ReplaceWith

Specifies a code fragment that can be used to suggest a replacement for a method in conjunction with the ReplaceWith lint check.

The expression parameter specified the replacement expression, which is interpreted in the context of the symbol being used and can reference members of the enclosing classes, etc.

For method calls, the replacement expression may contain parameter names of the method being replaced, which will be substituted with actual arguments used in the call being replaced:

@ReplaceWith(expression = "event.getActionType(slot)")
static int getActionType(AccessibilityEvent event, int slot) { ... }

Summary

Public constructors

Public methods

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2025-07-17 UTC.