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
@Sottti
Sottti / Public.kt
Last active December 3, 2018 07:20
// 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)
}
// 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)
}
@Sottti
Sottti / Private.kt
Last active November 28, 2018 07:56
Kotlin Access Modifiers: private
// 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)
}
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 = ""
@Entity(tableName = "Users")
data class UserRM(
@PrimaryKey
@ColumnInfo(name = "id")
val id: Int,
@ColumnInfo(name = "name")
val name: String,
@Sottti
Sottti / Copy.kt
Last active September 22, 2018 07:56
val steveJobs= User("Steve Jobs", 56)
val steveJobsToday= steveJobs.copy(age = 63)
data class User(val name: String, val age: Int) {
var address : String = ""
}
val steveJobs= User("Steve Jobs", 56)
fun print() {
val (name, age) = steveJobs
println("$name, $age years of age") // prints "Steve Jobs, 56 years of age"
steveJobs.component1() // name
steveJobs.component2() // age
}
@Sottti
Sottti / User.java
Last active September 22, 2018 08:02
public class User {
private String name;
private int age;
public User(String name, int age) {
this.name = name;
this.age = age;
}
@Sottti
Sottti / MyActivity.java
Last active January 18, 2021 09:29
Handles clicks on a EditText right drawable
[...]
mEditText.setOnTouchListener(
new OnEditTextRightDrawableTouchListener(mEditText) {
@Override
public void OnDrawableClick() {
// The right drawable was clicked. Your action goes here.
}
});
[...]