1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.compose.runtime
18 
19 /**
20  * [StableMarker] marks an annotation as indicating a type is stable. A stable type obeys the
21  * following assumptions,
22  * 1) The result of [equals] will always return the same result for the same two instances.
23  * 2) When a public property of the type changes, composition will be notified.
24  * 3) All public property types are stable.
25  *
26  * A type that is immutable obeys the above assumptions because the public values will never change.
27  * The [Immutable] annotation is provided to mark immutable types as stable.
28  *
29  * An object whose public properties do not change but is not immutable (for example, it has private
30  * mutable state or uses property delegation to a [androidx.compose.runtime.MutableState] object,
31  * but is otherwise immutable), should use the [Stable] annotation.
32  *
33  * Mutable object that do not notify composition when they changed should not be marked as stable.
34  *
35  * When all types passed as parameters to a [androidx.compose.runtime.Composable] function are
36  * marked as stable then the parameter values are compared for equality based on positional
37  * memoization and the call is skipped if all the values are the equal to the previous call.
38  *
39  * Primitive value types (such as Int, Float, etc), String and enum types are considered, a priori,
40  * stable.
41  *
42  * @see Immutable
43  * @see Stable
44  */
45 @MustBeDocumented
46 @Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS)
47 @Retention(AnnotationRetention.BINARY)
48 public annotation class StableMarker
49