Todd Ginsberg
Kotlin for 4 years Java for 20 years
Netspend - Payment company in Austin
Kotlin - Satically typed language developed by JetBrains. Released under Apache 2 License.
designed as a General Purpose language
Targets multple backends - Java 6 or 8, JavaScript, Native platforms due to LLVM
100% interoperable with Java
Designed to avoid Defects (Null Pointer Exceptions, etc.)
Lots of small improvements that add up
More compact, lots of good syntactic sugar reduces cognitive load
189,000 Null-safety issues on Github.
"WHat is a null pointer exception" shows up 15,000 times on Stack Overflow
Kotlin steals good features from other languages - Groovy, Python, etc.
Good Community
Spring Framework 5.0 has Kotlin support, 5.2 is better.
- Nullability works right.
- Really good examples in Kotlin in the docs
Roman Elizarov - JetBrains
The most common case is the default. Less boilerplate means less cogniitive load.
val vs var - Invariants are first class citizens.
Kotlin - Semicolons are optional
String interpolation: "foo $bar"
Type inference makes types optional most of the time.
Kotlin has syntactic sugar for "=="
Ref equality is "===" as in Javascript
Triple quotes for strings, just like python
Null Safety.
Traversal operator:
var foo : String? = "Austin"
foo?.toUpperCase()
Kotlin override:
val lowest: Int? = listOf(1,2,3).min()!!
When - "Case" on steroids.
When allows smart casting:
when (x) {
is Int -> print x % 2 == 0)
is String -> print( x.length +1)
is
}
Don't need to specify implement or extends, just use ":"
Oope can be extend, otherwise it can't.
Kotlin has no "new" keyword
Autogenerated setters and getters. Auto-calling getters and setters
Kotlin has data classes (includes toString, hashCode and equals) Data classes include copy constructors
Spring Boot 2.2 allows data classess as @ConfiguraitonProperties
Kotlin allows defaultable parameters.
Kotlin allows named parameters to be called in different orders.
- Be careful because parameter names are now part of the API spec
Kotlin allows you to "push" functions into objects:
fun Int.isEven() : boolean {
return it % 2 == 0
}
Apply is awesome:
val p = Person().apply {
name="Todd",
age=21
}
functions are final by default, unless you open them. arguments are always final functions can be defined outside of a class (like static functions, kind of) Kotlin supports tail recursive functions
Checked excepitons aren't mandatory, they're all Runtime, just deal with it.