...
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 Logger.info("Hello World")
52
53 a %= 2
54 a && b
55 a *= 2
56 a++
57 b+=2
58 b--
59 a-=1
60 a /= 2
61 a <= b
62 b == a
63 a >= b
64 nullable!!
65 a != b
66 a || b
67 a?.foo
68 a ?: b
69}
70
71class B // no braces
72
73data class C(
74 val s: String
75)
76
77fun moreOperators(arg: Any?) {
78 when(arg) {
79 !is Int -> { }
80 is Number -> {}
81 in emptyList<Int>() -> { }
82 }
83
84 if(arg !== Boolean)
85 println(arg === Unit)
86}
87
88@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION,
89 AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION)
90@Retention(AnnotationRetention.SOURCE)
91annotation class Annotated
92
93@Annotated class A {
94 @Annotated fun a(
95 @Annotated param: Int
96 ) {
97
98 @Annotated val y = 0
99
100 }
101}
102
103open class TUpper
104fun <T: TUpper, R: Any?> generic() = 123
105
106class Holder <in A, out B, C: TUpper>
107
108class Holder2 <T>
109
110var holder1: Holder<Int, String, *>? = null
111
112class Some(
113 val holder2: Holder<Int, String, *>? = null
114) {
115 var holder3: Holder<Int, String, *>? = null
116 fun example() {
117 var holder4: Holder<Int, String, *>? = null
118 }
119}
120fun <T : Comparable<T>> sort(list: List<T>) {
121
122}
123
124class X {
125 companion object {
126 }
127 suspend inline fun <reified T> generic(t: T) { print(T::class.simpleName) }
128} // eof comment
View as plain text