Skip to content

Instantly share code, notes, and snippets.

View igorwojda's full-sized avatar

Igor Wojda igorwojda

View GitHub Profile
class Person (var name:String, var lastName:String, var weight:Double) {
val fullName = "$name $lastName"
}
class Person () {
fun run() { /*doSth*/ }
fun walk() { /*doSth*/ }
fun jump() { /*doSth*/ }
}
class Person (var name:String, var lastName:String, var weight:Double) {
//..
fun jump() {
weight -= 0.1
/*doSth*/
}
}
person.name = "Igor"
person.weight = 79
person.jump()
person.jump()
person.jump()
class Person (var name:String, var lastName:String, var weight:Double) {
val fullName
get() = "$name $lastName"
}
//BAD
class Person () {
private var weight:Double = 0
fun setWeight(weight:Double) {
this.weight = weight
}
fun getWeight(): Double {
return weight
fun main(args: Array<String>) {
val range = 1..10000
logTime("benchmarkPlusOperator") { benchmarkPlusOperator(range) }
logTime("benchmarkStringAppend") { benchmarkStringAppend(range) }
}
fun benchmarkPlusOperator(range:IntRange) {
var str = ""
range.forEach { str += "abc" }
public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
textView.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
//do something
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//do something
}
class View {
private var beforeTextChangedListener: (() -> Unit)? = null
private var afterTextChangedListener: (() -> Unit)? = null
private var onTextChangedListener: (() -> Unit)? = null
fun setBeforeTextChangedListener(listener: () -> Unit) {
beforeTextChangedListener = listener
}
fun setAfterTextChangedListener(listener: () -> Unit) {