Skip to content

Instantly share code, notes, and snippets.

@jamesmporter
jamesmporter / Calculator.java
Created March 21, 2019 10:34
Kotlin vs Java: When to Switch
public class Calculator {
public static double calculate (double a, String op, double b) throws Exception {
switch (op) {
case "plus":
return a+b;
case "minus":
return a-b;
case "div":
return a/b;
case "times":
@jamesmporter
jamesmporter / Person.java
Last active March 21, 2019 10:47
Data classes vs Boilerplate
public class Person {
private String name;
private String email;
private int age;
public Person(String name, String email, int age) {
this.name = name;
this.email = email;
this.age = age;
}
mLiveData.observe(this, Observer {
when (it) {
0 -> zero()
1 -> one()
null -> mLiveData.postValue(0) //Initialise
else -> many()
}
})