Kotlin

661 readers
1 users here now

Kotlin is a statically typed programming language for the JVM, Android, JavaScript, and native.

Subreddit rules:

Resources:

founded 1 year ago
MODERATORS
1
 
 

Hi everyone, I am learning kotlin as my first language(I have a bit of python knowledge mostly useless stuffs) I am following the android tutorial for kotlin and now I am 100% lost at the tip calculator in kotlin here. What should/could I do to improve my situation? Any recommend would help me a lot. Thank!

2
3
 
 
4
5
6
7
8
9
 
 

I bumped into this interesting behavior around unsigned types. At first I was confused why UInt doesn't extend Number, but as I was experimenting, it got weirder. It sometimes is a Number (see case c below) and sometimes isn't (see case d)?!

val a: Int = 12
a is Number // true

val b: UInt = 12u
b is Number // doesn't compile, `Incompatible types: Number and UInt`

val c: UInt = 12u
(c as Any) is Number // true, Idea says "No cast needed"

val d: Any = 12u
d is Number // false

I guess this is partly legacy of Java, which doesn't have unsigned types, and partly effect of UInt being value class. I'm curious if someone has a deeper explanation.