DEV Community

Coder
Coder

Posted on • Originally published at itscoderslife.wordpress.com on

3 1

Android-Kotlin Digest #2 – Basic Types

Back again with Kotlin I learnt.

Kotlin runs on Java Virtual Machine (JVM).

Syntax for declaring variables:

Mutable: var name: Type = value

Immutable: val name: Type = value

Type Bit width
Double 64
Float 32
Long 64
Int 32
Short 16
Byte 8

Kotlin 1.1 supports underscores ( _ ) in numeric values for readability:

val mySalary = 1_000_000

val myCreditCardBill = 20_000

Difference between == and === :

val a : Int = 10

val b : Int = 10

(a == b) // gives true

(a === b) // gives true

Note: Here primitive types are compared.

When the primitive types are nullable it is turned into references and following is the result:

val a : Int? = 10

val b : Int? = 10

(a == b) // gives true

(a === b) // gives false

Note: Here a and b becomes references and hence comparision with === results false.

Type converters:

‘c’.toInt()

80.toString()

A raw string is delimited by a triple quote ( “”” ), contains no escaping and can contain newlines and any other characters:

val text = “””

for (c in “foo”)

    print(c)
Enter fullscreen mode Exit fullscreen mode

“””

You can remove leading whitespace with trimMargin() function:

val text = “””

|Tell me and I forget.

|Teach me and I remember.

|Involve me and I learn.

|(Benjamin Franklin)
Enter fullscreen mode Exit fullscreen mode

“””.trimMargin()

— Happy Coding —

Sentry mobile image

App store rankings love fast apps - mobile vitals can help you get there

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read full post →

Top comments (0)

Billboard image

📊 A side-by-side product comparison between Sentry and Crashlytics

A free guide pointing out the differences between Sentry and Crashlytics, that’s it. See which is best for your mobile crash reporting needs.

See Comparison

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay