.map(Person::getName).collect(Collectors.toList()); 1 "Advancing Android Development with Kotlin", Jake Wharton Introduction to Kotlin Pt. 1, Richard Cirerol
• Use Apache Collections • Use RxJava (with Retrolambda) List<String> list = Observable.from(people) .map(Person::getName).toBlocking().toList() 1 "Advancing Android Development with Kotlin", Jake Wharton Introduction to Kotlin Pt. 1, Richard Cirerol
easiest possible statement so very tedious and VERBOSE.1 • For anonymous classes, use Retrolambda instead • Otherwise, you're SOL 1 "Advancing Android Development with Kotlin", Jake Wharton Introduction to Kotlin Pt. 1, Richard Cirerol
Scala the Good Parts, Java++ or simply a decent general purpose language that won't require the blood of your first born. -- James Hughes (https://yobriefca.se/blog/2016/02/24/ kotlin-2-years-on/) Introduction to Kotlin Pt. 1, Richard Cirerol
was in November 2010 • v1.0 RTW in February 2016 • 1.0.3 is current stable • 1.0.4 is in EAP • Additional updates for performance, tooling, bug fixes Introduction to Kotlin Pt. 1, Richard Cirerol
Not likely. • JetBrains is building its products on Kotlin • JetBrains is not building Kotlin as a revenue source • Kotlin is open-source (125+ contributors, including 20+ from JetBrains) Introduction to Kotlin Pt. 1, Richard Cirerol
of the standard library // Java 8 stream/collect List<String> list = people.stream() .map(Person::getName).collect(Collectors.toList()); // Kotlin val list = people.map { it.name } Introduction to Kotlin Pt. 1, Richard Cirerol
standard library // Java 8 stream/collect List<String> list = people.stream() .map(Person::getName).collect(Collectors.toList()); // Kotlin val list = people.map { it.name } //OR val list = people.map { person -> person.name } Introduction to Kotlin Pt. 1, Richard Cirerol
the standard library fun String.ellipsize(size: Int): String { return "${this.substring(0, size)}..." } "Hello, Kotlin".ellipsize(5) // Hello... Introduction to Kotlin Pt. 1, Richard Cirerol
= null // Must make type nullable val name: String? = null // compiler exception, name can be null now, cannot call length // length type is inferred val length = name.length // Inline check for null, name?.length evaluates to `null` if name==null // Provide alternative using Elvis operator val length = name?.length ?: 0 // Can force compiler to assume not null using double-bang // Possible NPE at runtime (but this is your own fault) val length = name!!.length Introduction to Kotlin Pt. 1, Richard Cirerol
lastName: String, val email: String) // has hashcode(), equals(), and toString() // v1.0 cannot subclass, v1.1 can subclass Introduction to Kotlin Pt. 1, Richard Cirerol
final Bar bar; private final String baz; public Foo(@NotNull Bar bar){ this(bar, "baz") } public Foo(@NotNull Bar bar, @NotNull String baz){ this.bar = bar; this.baz = baz; } } //kotlin class Foo(val bar:Bar, val baz:String = "baz") Introduction to Kotlin Pt. 1, Richard Cirerol
final Bar bar; private final String baz; public Foo(@NotNull Bar bar){ this(bar, "baz") } public Foo(@NotNull Bar bar, @NotNull String baz){ this.bar = bar; this.baz = baz; } } //kotlin @JvmOverloads class Foo(val bar:Bar, val baz:String = "baz") Introduction to Kotlin Pt. 1, Richard Cirerol
{ override fun onClick(v: View) { doSomething("Click") } }) 2 http://antonioleiva.com/functional-programming-android-kotlin-lambdas/ Introduction to Kotlin Pt. 1, Richard Cirerol