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