Skip to content

Instantly share code, notes, and snippets.

View shruti-basil-hs's full-sized avatar

shruti-basil-hs

View GitHub Profile
text_foo.setText(“foo”);
textView  = (TextView) findViewById(R.id.text_foo);
textView.setText(“foo”);
View.visible() {
this.visibility = View.Visible
}
val w = Window()
with(w) {
setWidth(100)
setHeight(200)
setBackground(RED)
}
fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f()
Person(name).apply { foo() };
//Equivalent 4 line Java code
Person getFoo(String name) {
Person person = new Person(name);
person.foo();
return person;
}
fun <T> T.apply(f: T.() -> Unit): T { f(); return this }
Person.getName().let { name ->
print(name)
}
// name is no longer visible here
fun <T, R> T.let(f: (T) -> R): R = f(this)
class Person(var name: String?) // the name property can be null
class Person(var name: String) // the name property cannot be null