101: Learning Kotlin – visibility modifiers, internal modifier, modules

Another day, another opportunity to learn more Kotlin. In this episode, Kaushik walks through the concept of visibility modifiers. How do the modifiers in Kotlin differ from the ones in Java? What is this new internal modifier? When should I use each of the operators?

Listen on to find out!

Direct download

Shownotes:

  • Excellent resource explaining visibility modifiers in Kotlin

    open class Outer {
        private val a = 1
        protected open val b = 2
        internal val c = 3
        val d = 4  // public by default
    
        protected class Nested {
            public val e: Int = 5
        }
    }
    
    class Subclass : Outer() {
        // a is not visible
        // b, c and d are visible
        // Nested and e are visible
    
        override val b = 5   // 'b' is protected
    }
    
    class Unrelated(o: Outer) {
        // o.a, o.b are not visible
        // o.c and o.d are visible (same module)
        // Outer.Nested is not visible, and Nested::e is not visible either 
    }