-
Notifications
You must be signed in to change notification settings - Fork 1
/
ReplaceDeprecated.kt
29 lines (25 loc) · 1.07 KB
/
ReplaceDeprecated.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.arindam.kotlin.x
/**
* Now that we have deprecated a function,
* we just have to replace it in 327 call sites 😨. Not anymore 😅
*
* Created by Arindam Karmakar on 22/7/19.
*/
fun increment(number: Int): Int = number + 1 // (1/5) Replacement for deprecated function.
@Deprecated(
message = "Boring name.", // (2/5) A deprecation message, to keep users informed.
replaceWith = ReplaceWith(
/*
* (3/5) Expression helps the IDE replace deprecated functions with a replacement
* in call sites. Please pay attention to (old) parameter names and order
* of those parameters in the replacement expression.
*/
"increment(count)",
"com.arindam.certification.training.kotlin.increment"
),
level = DeprecationLevel.WARNING // (4/5) Can be WARNING, ERROR or HIDDEN
)
fun addOne(count: Int): Int = count + 1
fun main() {
println(addOne(0)) // (5/5) Use the IDE's quick-fix feature to replace deprecated function calls.
}