/
kotlin.actual
128 lines (100 loc) · 2.29 KB
/
kotlin.actual
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package X
import A
import B.*
fun main(args: Array<String>) {
val ` + "with spaces" + ` = "hello"
val multiline = """1
2"""
StringBuilder().apply {
append(multiline)
}
val unsigned = 0x00UL + 123u + 76.54
}
/*
*/
fun nullable(nullable: String?): Int = nullable?.length ?: 0
fun nullable2(nullable: String?): Int = nullable?.length ?: run {
1 + 2
}
val rawStringWithQuotes = """
Hello "example" ${1 + 2}
And now { Just the braces }
Escapes here don't work so this is just text \t \n \u1234 $ \$
"""
fun returnsSomething(): Int {
return "".length
}
fun returnsSomethingElse(): Int = "\\\n".length
val character = '"'
val escapedCharacter = '\"'
// escaping a double quote character inside a character is optional
val stringWithSingleQuote = "'"
typealias MySecretAlias<A, B> = (A, B) -> Unit
val impl : MySecretAlias<Int, Int> = { a, _ -> Unit }
fun someOperators(a: Int, b: Int) {
var c : Int = 123
println("This is an example a = $a and the sum is ${a + b} ${ A.foo() }")
println( a % b)
println(c in a..b)
Logger.info("Hello World")
a %= 2
a && b
a *= 2
a++
b+=2
b--
a-=1
a /= 2
a <= b
b == a
a >= b
nullable!!
a != b
a || b
a?.foo
a ?: b
}
class B // no braces
data class C(
val s: String
)
fun moreOperators(arg: Any?) {
when(arg) {
!is Int -> { }
is Number -> {}
in emptyList<Int>() -> { }
}
if(arg !== Boolean)
println(arg === Unit)
}
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION,
AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class Annotated
@Annotated class A {
@Annotated fun a(
@Annotated param: Int
) {
@Annotated val y = 0
}
}
open class TUpper
fun <T: TUpper, R: Any?> generic() = 123
class Holder <in A, out B, C: TUpper>
class Holder2 <T>
var holder1: Holder<Int, String, *>? = null
class Some(
val holder2: Holder<Int, String, *>? = null
) {
var holder3: Holder<Int, String, *>? = null
fun example() {
var holder4: Holder<Int, String, *>? = null
}
}
fun <T : Comparable<T>> sort(list: List<T>) {
}
class X {
companion object {
}
suspend inline fun <reified T> generic(t: T) { print(T::class.simpleName) }
} // eof comment