Deprecated

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.3)
@Target([AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.TYPEALIAS]) annotation class Deprecated

Marks the annotated declaration as deprecated.

A deprecated API element is not recommended to use, typically because it's being phased out or a better alternative exists.

To help removing deprecated API gradually, the property level could be used. Usually a gradual phase-out goes through the "warning", then "error", then "hidden" or "removed" stages:

  • First and by default, DeprecationLevel.WARNING is used to notify API consumers, but not to break their compilation or runtime usages.
  • Then, some time later the deprecation level is raised to DeprecationLevel.ERROR, so that no new Kotlin code can be compiled using the deprecated API.
  • Finally, the API is either removed entirely, or hidden (DeprecationLevel.HIDDEN) from code, so its usages look like unresolved references, while the API remains in the compiled code preserving binary compatibility with previously compiled code.

Constructors

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

<init>

Marks the annotated declaration as deprecated.

<init>(
    message: String, 
    replaceWith: ReplaceWith = ReplaceWith(""), 
    level: DeprecationLevel = DeprecationLevel.WARNING)

Properties

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

level

Specifies how the deprecated element usages are reported in code. See the DeprecationLevel enum for the possible values.

val level: DeprecationLevel
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

message

The message explaining the deprecation and recommending an alternative API to use.

val message: String
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

replaceWith

If present, specifies a code fragment which should be used as a replacement for the deprecated API usage.

val replaceWith: ReplaceWith

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-deprecated/index.html