This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class User( | |
val name: String, | |
val surname: String = "", | |
val address: String = "") { | |
class Builder { | |
private lateinit var name : String | |
private var surname : String = "" | |
private var address : String = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Private.kt file | |
// Visible just inside this file | |
private const val numberThree = 3 | |
// Visible just inside this file | |
private class User() { | |
// Visible just inside the user class | |
private val numberEight = numberThree.plus(5) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Protected.kt file | |
// Visible inside this file | |
private const val numberThree = 3 | |
// Visible inside this file | |
private open class User() { | |
// Visible inside the User class and subclasses | |
protected val numberEight = numberThree.plus(5) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Public.kt file | |
// Visible everywhere | |
public const val numberThree = 3 | |
// Visible everywhere | |
public open class User() { | |
// Visible to everyone with visibility on the User class | |
public val numberEight = numberThree.plus(5) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AnotherFile.kt file | |
// numberThree is visible to any other file because it's public | |
// numberEight is visible to any other file because User and numberEight are public | |
// numberEleven is visible to any other file because Moderator and numberEleven are public | |
private const val numberTwentyTwo = numberThree + User().numberEight + Moderator().numberEleven |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Internal.kt file | |
// Visible to everyone in the same module | |
internal const val numberThree = 3 | |
// Visible to everyone in the same module | |
internal open class User() { | |
// Visible to everyone in the same module that has visibility on User | |
internal val numberEight = numberThree.plus(5) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SameModule.kt file | |
// numberThree is visible because this file is in the same module than Internal.kt | |
// numberEight is visible because this file is in the same module than User | |
private const val numberEleven = numberThree.plus(User().numberEight) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DifferentModule.kt file | |
// ERROR: numberThree is not visible because this file is in a different module than Internal.kt | |
// ERROR: numberEight is not visible because User() is in a different module than Internal.kt | |
private const val numberEleven = numberThree.plus(User().numberEight) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// User is public | |
// The User primary constructor is private | |
class User private constructor(id : Int) { | |
// ... | |
} | |
// Moderator is internal | |
// The Moderator primary constructor is private | |
internal Moderator private constructor(id : Int) { | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Overridden.kt | |
public open class User { | |
protected open fun getAge() = 16 | |
} | |
public class Moderator : User() { | |
// getAge() inherits the protected modifier as default | |
override fun getAge() = 18 | |
} |