Yaz覺m Kurallar覺

今 Adland覺rmalar

1
// Test i癟in 繹zel adland覺rmalar
2
class MyTestCase {
3
@Test fun `ensure everything works`() { /*...*/ }
4
5
@Test fun ensureEverythingWorks_onAndroid() { /*...*/ }
6
}
7
8
// Property
9
val isEmpty: Boolean get() = size == 0
Copied!

栽儭 Koul Kullan覺mlar覺

1
when (foo) {
2
true -> bar() // good
3
false -> { baz() } // bad
4
else -> {}
5
}
6
7
// 2 deiken i癟in if 繹neriliyor
8
if (x == null) /* ... */ else /* ... */
Copied!

儭 Zincir Kullan覺mlar

  • ? bata olur
1
val anchor = owner
2
?.firstChild!!
3
.siblings(forward = true)
4
.dropWhile { it is PsiComment || it is PsiWhiteSpace }
Copied!

Keyword S覺ras覺

1
public / protected / private / internal
2
expect / actual
3
final / open / abstract / sealed / const
4
external
5
override
6
lateinit
7
tailrec
8
vararg
9
suspend
10
inner
11
enum / annotation
12
companion
13
inline
14
infix
15
operator
16
data
Copied!

Kotlin Doc

1
// Avoid doing this:
2
3
/**
4
* Returns the absolute value of the given number.
5
* @param number The number to return the absolute value for.
6
* @return The absolute value.
7
*/
8
fun abs(number: Int) { /*...*/ }
9
10
// Do this instead:
11
12
/**
13
* Returns the absolute value of the given [number].
14
*/
15
fun abs(number: Int) { /*...*/ }
Copied!

儭 Function Builder

  • 栽儭 from<Name> ad覺 tercih edilmeli
  • fromPolar
1
class Point(val x: Double, val y: Double) {
2
companion object {
3
fun fromPolar(angle: Double, radius: Double) = Point(...)
4
}
5
}
Copied!

Kaynaklar

Document Kotlin code: KDoc and Dokka | Kotlin
Kotlin Help