button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
doSomethingAmazing();
}
});
button.setOnClickListener {
doSomethingAmazing()
}
fun View.onClick(listener: (View) -> Unit){
this.setOnClickListener(listener)
}
button.onClick {
}
// Java
List<String> list = Arrays.asList("1", "2", "3", "4");
Integer maxValue = null;
for(String item : list){
Integer value = Integer.parseInt(item);
Integer doubledValue = value * 2;
if(doubledValue < 6) {
if(maxValue == null){
maxValue = doubledValue;
} else {
maxValue = (doubledValue > maxValue) ? doubledValue : maxValue;
}
}
}
val list = listOf("1", "2", "3", "4")
val max = list.map { it.toInt() * 2 } .filter { it > 6 } .max()
fun uploadValue(value: Any, callback: (response: Response?, error: Error?) -> Unit) {
// Do something amazing and async...
asyncOperation {
callback(response, error)
}
}
uploadValue("HARRY POTTER") { success, error ->
}