Skip to content

Instantly share code, notes, and snippets.

View Sottti's full-sized avatar
💡
"Success is simply a matter of luck. Ask any failure"

Pablo Costa Sottti

💡
"Success is simply a matter of luck. Ask any failure"
View GitHub Profile
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="34dp"
android:viewportWidth="100"
android:viewportHeight="34">
<path
android:fillColor="@color/car_logo_fill"
android:pathData="M1.3,2l-1,1s0.2,0.1 0.2,0l0.4,-0.3 0.4,0.3 1.1,0.6 1.3,0.6h1l2.2,0.2L10.7,4.4a162.2,162.2 0,0 0,6 0L22,4.4l1.5,0.1 1.3,0.2 0.3,0.2L25.1,5h0.2l0.1,-0.2 0.1,-0.2v-0.3l-0.7,-0.1A37.8,37.8 0,0 1,21 3a18.2,18.2 0,0 0,-4.7 -0.6L11.3,2.4l-1,-0.1h-1l-0.5,-0.1L8.8,2h2.1L12,2h2.8A116.5,116.5 0,0 1,20 2l1.7,0.4c0.6,0 1.1,0.3 1.8,0.5l2,0.5 1.7,0.1h2.5l3,0.1c0.5,0 3,0.2 3.8,0.4 1.3,0.2 2.6,1.1 2.8,2.2 0.2,1.5 -1.4,3 -1.5,4.4l-0.1,1 -0.3,0.3 0.1,0.2s0,-0.2 0.2,-0.3a14.7,14.7 0,0 1,1.3 -2v-0.7l0.6,-1.2L41,6.7l1,-1c0.2,-0.2 0.5,-0.5 0.6,-0.8 0.2,-0.2 0.2,-0.6 0.2,-0.9l-0.3,-0.6c0,-0.1 0,-0.4 -0.2,-0.5l-0.5,-0.3 -0.3,-0.4 -0.5,-0.1 -1.4,-0.2a39.3,39.3 0,0 0,-9.5 -0.1h-2l-3.7,-0.2 -3,-0.2h-6.8l-2.1,0.2 -2,0.1L5.7,1.7l-1.6,-0.1 -1.8,-0.2h-0.7l-0.4,0.5zM42.1,1.8l-0.6,0.3
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="100"
android:viewportHeight="100">
<group>
<clip-path
android:pathData="M0,0h100v100H0z"/>
<path
android:fillColor="@color/car_logo_fill"
open class User(val userId: Int, val userName: String)
class Editor(userId: Int, userName: String, val rank: Int) : User(userId, userName)
class Moderator(userId: Int, userName: String, val type: Int) : User(userId, userName)
class Staff(userId: Int, userName: String, val department: String) : User(userId, userName)
// OverridenFromAnotherFile.kt
// Error: getAge() is not visible because is protected
val userAge = User().getAge()
// Error: getAge() is not visible because inherits the protected modifier
val moderatorAge = Moderator().getAge()
// getAge() is visible because the modifier is declared explicitly as public
val staffAge = Staff().getAge()
// 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
}
// 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) {
// ...
// 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)
// 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)
// 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)
}
// 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