kotlin: let's make android great again
TRANSCRIPT
![Page 1: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/1.jpg)
ㅍ
ExtendedSeoul
![Page 2: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/2.jpg)
ExtendedSeoul
![Page 3: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/3.jpg)
Statically typed programming language for the JVM, Android and the browser
100% interoperable with Java™
![Page 4: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/4.jpg)
ㅍ
ExtendedSeoul
![Page 5: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/5.jpg)
ExtendedSeoulExtendedSeoul
![Page 6: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/6.jpg)
ExtendedSeoulExtendedSeoul
![Page 7: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/7.jpg)
ExtendedSeoulExtendedSeoul
![Page 8: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/8.jpg)
ExtendedSeoul
![Page 9: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/9.jpg)
ExtendedSeoul
![Page 10: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/10.jpg)
ExtendedSeoul
![Page 11: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/11.jpg)
ExtendedSeoulExtendedSeoul
![Page 12: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/12.jpg)
ExtendedSeoul
![Page 13: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/13.jpg)
ExtendedSeoul
![Page 14: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/14.jpg)
ExtendedSeoul
![Page 15: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/15.jpg)
ExtendedSeoulExtendedSeoul
![Page 16: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/16.jpg)
ㅍ
ExtendedSeoul
![Page 17: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/17.jpg)
MyActivity.java
btnDoIt = (Button) findViewById(R.id.btn_do_it);
![Page 18: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/18.jpg)
MyActivity.java
btnDoIt = (Button) findViewById(R.id.btn_do_it); btnDoIt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO } });
![Page 19: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/19.jpg)
MyActivity.java
btnDoIt = (Button) findViewById(R.id.btn_do_it); btnDoIt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO } });
![Page 20: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/20.jpg)
WithRxJava.java
Observable.fromArray(1, 2, 3, 4, 5) .map(new Function<Integer, String>() { @Override public String apply(Integer param) { return "A" + param; } });
![Page 21: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/21.jpg)
WithRxJava.java
Observable.fromArray(1, 2, 3, 4, 5) .map(new Function<Integer, String>() { @Override public String apply(Integer param) { return "A" + param; } });
![Page 22: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/22.jpg)
WithRxJava.java
Observable.fromArray("1", "2", "3", "4", "5") .map(new Function<Integer, String>() { @Override public String apply(Integer param) { return "A" + param; } });
![Page 23: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/23.jpg)
WithRxJava.java
Observable.fromArray("1", "2", "3", "4", "5") .map(new Function<Integer, String>() { @Override public String apply(Integer param) { return "A" + param; } });
![Page 24: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/24.jpg)
WithRxJava.java
Observable.fromArray("1", "2", "3", "4", "5") .map(new Function<String, String>() { @Override public String apply(String param) { return "A" + param; } });
![Page 25: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/25.jpg)
User.java
String getAddress() { ... }
User user = getCurrentUser(); user.getAddress().toUpperCase();
![Page 26: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/26.jpg)
ExtendedSeoul
I call it my billion-dollar mistake. This has led to innumerable errors … probably caused a billion dollars of pain and damage in the last forty years.
ExtendedSeoul
- Tony Hoare
![Page 27: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/27.jpg)
User.java
String getAddress() { return this.address; }
User user = getCurrentUser(); user.getAddress().toUpperCase();
![Page 28: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/28.jpg)
User.java
String getAddress() { return null == this.address ? "" : this.address; }
User user = getCurrentUser(); user.getAddress().toUpperCase();
![Page 29: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/29.jpg)
User.java
@Nullable String getAddress() { return this.address; }
User user = getCurrentUser(); user.getAddress().toUpperCase();
![Page 30: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/30.jpg)
User.java
@NonNull String getAddress() { return null == this.address ? "" : this.address; }
User user = getCurrentUser(); user.getAddress().toUpperCase();
![Page 31: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/31.jpg)
ㅍ
ExtendedSeoul
![Page 32: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/32.jpg)
MyActivity.java
Button btnFoo; TextView tvBar;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
btnFoo = (Button) findViewById(R.id.btn_foo); tvBar = (TextView) findViewById(R.id.tv_bar); ... }
![Page 33: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/33.jpg)
MyActivity.java
Button btnFoo; TextView tvBar;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
btnFoo = (Button) findViewById(R.id.btn_foo); tvBar = (TextView) findViewById(R.id.tv_bar); ... }
![Page 34: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/34.jpg)
Intents.java
Intent intent = new Intent(this, OtherActivity.class); intent.putExtra("id", 10L); intent.setFlag(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent);
![Page 35: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/35.jpg)
ExtendedSeoulExtendedSeoul
![Page 36: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/36.jpg)
MyActivity.java
btnDoIt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO } });
![Page 37: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/37.jpg)
MyActivity.kt
btnDoIt.setOnClickListener(object : View.OnClickListener() { override fun onClick(v: View) { // TODO } })
![Page 38: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/38.jpg)
MyActivity.kt
btnDoIt.setOnClickListener({ v: View -> // TODO })
![Page 39: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/39.jpg)
MyActivity.kt
btnDoIt.setOnClickListener({ v -> // TODO })
![Page 40: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/40.jpg)
MyActivity.kt
btnDoIt.setOnClickListener({ it.context // View.context })
![Page 41: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/41.jpg)
MyActivity.kt
btnDoIt.setOnClickListener { it.context // View.context }
![Page 42: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/42.jpg)
StandardLibrary.kt
val people : List<String> = ..
people.filter { it.startsWith('S') } .filter { it.length < 10 } .onEach { it.toUpperCase() } .forEach { println(it) }
![Page 43: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/43.jpg)
StandardLibrary.kt
val people : List<String> = ..
people.filter { it.startsWith('S') } .filter { it.length < 10 } .onEach { String::toUpperCase() } .forEach { ::println }
![Page 44: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/44.jpg)
StandardLibrary.kt
val people : List<String> = .. people.stream() .filter { it.startsWith('S') } .filter { it.length < 10 } .map(String::toUpperCase) .forEach(::println)
![Page 45: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/45.jpg)
User.java
@Nullable String getAddress() { return this.address; }
User user = getCurrentUser(); user.getAddress().toUpperCase();
![Page 46: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/46.jpg)
User.java
// class User var address: String? = null
//// val user : User = getCurrentUser() user.address?.toUpperCase()
![Page 47: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/47.jpg)
User.java
// class User var address: String? = null
//// val user : User = getCurrentUser() user.address?.toUpperCase()
![Page 48: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/48.jpg)
User.java
// class User var address: String? = null
//// val user : User = getCurrentUser() user.address?.toUpperCase()
![Page 49: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/49.jpg)
User.java
// class User var address: String? = null
//// val user = getCurrentUser() user.address?.toUpperCase()
![Page 50: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/50.jpg)
User.java
@NonNull String getAddress() { return null == this.address ? "" : this.address; }
User user = getCurrentUser(); user.getAddress().toUpperCase();
![Page 51: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/51.jpg)
User.java
// class User var address: String? = null get() = field ?: ""
//// val user = getCurrentUser() user.address.toUpperCase()
![Page 52: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/52.jpg)
User.java
// class User var address: String? = null get() = field ?: ""
//// val user = getCurrentUser() user.address.toUpperCase()
![Page 53: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/53.jpg)
User.java
// class User var address: String? = null get() = field ?: ""
//// val user = getCurrentUser() user.address.toUpperCase()
![Page 54: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/54.jpg)
MyActivity.java
Button btnFoo; TextView tvBar;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
btnFoo = (Button) findViewById(R.id.btn_foo); tvBar = (TextView) findViewById(R.id.tv_bar); ... }
![Page 55: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/55.jpg)
MyActivity.kt
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main)
btn_foo // (Button) findViewById(R.id.btn_foo) tv_bar // (TextView) findViewById(R.id.tv_bar) ... }
![Page 56: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/56.jpg)
Intents.java
Intent intent = new Intent(this, OtherActivity.class); intent.putExtra("id", 10L); intent.setFlag(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent);
![Page 57: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/57.jpg)
Intents.kt
val intent = Intent(this, OtherActivity::class.java) intent.putExtra("id", 10L) intent.setFlag(Intent.FLAG_ACTIVITY_SINGLE_TOP) startActivity(intent)
![Page 58: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/58.jpg)
Intents.kt
startActivity( intentFor<SomeOtherActivity>("id" to 10L).singleTop())
![Page 59: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/59.jpg)
Collections.kt
val mutableList : MutableList<String> = mutableListOf(“foo", "bar", "baz") mutableList.add("fizz")
val immutableList : List<String> = listOf("foo", "bar", "baz") immutableList.add("fizz")
![Page 60: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/60.jpg)
Collections.kt
val mutableList : MutableList<String> = mutableListOf(“foo", "bar", "baz") mutableList.add("fizz")
val immutableList : List<String> = listOf("foo", "bar", "baz") immutableList.add("fizz")
![Page 61: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/61.jpg)
Collections.kt
val emptyStringList = listOf<String>() val cities = listOf("Seoul", "Busan") val mutableCities = mutableListOf("Seoul, Busan")
val emptyStringSet = setOf<String>() val cities = setOf("Seoul", "Busan") val mutableCities = mutableSetOf("Seoul, Busan")
![Page 62: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/62.jpg)
Collections.kt
val pair : Pair<String, String> = Pair("Seoul", "SEO")
![Page 63: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/63.jpg)
Collections.kt
val pair : Pair<String, String> = Pair("Seoul", "SEO")
// with stdlib val pair : Pair<String, String> = "Seoul" to "SEO"
![Page 64: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/64.jpg)
Person.java
public class Person { String name; String address;
Person(String name, String address) { this.name = name; this.address = address; }
public String getAddress() { return address; }
.. }
![Page 65: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/65.jpg)
Person.javapublic class Person {
String name;
String address;
Person(String name, String address) { this.name = name; this.address = address; }
public String getAddress() { return address; }
public void setAddress(String address) { this.address = address; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false;
Person person = (Person) o;
if (name != null ? !name.equals(person.name) : person.name != null) return false; return address != null ? address.equals(person.address) : person.address == null;
}
@Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + (address != null ? address.hashCode() : 0); return result; } }
![Page 66: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/66.jpg)
Person.kt
data class Person(val name: String, val address: String)
![Page 67: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/67.jpg)
MyToast.kt
Toast.makeText(applicationContext, "Hello, Kotlin!", Toast.LENGTH_SHORT).show()
![Page 68: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/68.jpg)
MyToast.kt
// Define an extension function on Context fun Context.toast(message: String) { Toast.makeText(this.applicationContext, message, Toast.LENGTH_SHORT).show() }
// available in class Context and its descendants toast("Hello, Kotlin!")
![Page 69: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/69.jpg)
ㅍ
ExtendedSeoul
![Page 70: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/70.jpg)
ㅍ
ExtendedSeoul
![Page 71: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/71.jpg)
ㅍ
ExtendedSeoul
![Page 72: Kotlin: Let's Make Android Great Again](https://reader033.vdocuments.us/reader033/viewer/2022052117/5a66d4657f8b9a3c0e8b584b/html5/thumbnails/72.jpg)
ExtendedSeoul
ㅍ
ExtendedSeoul