Created
December 7, 2017 18:28
-
-
Save evanchooly/d03892250e25e19c3640b28b838108aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kotlin from the Ground Up | |
================================ | |
* Files | |
* temp.kt | |
* obviously the starting point but a more robust compilation unit than in Java | |
* can contain bare functions, classes, objects, even properties | |
* Properties | |
* we'll start here because every things builds up from this | |
* *name* : *type* | |
* var/val | |
* type inference | |
* val x = 1 | |
* not for nulls obviously | |
* lateinit | |
* see any DAO in javabot | |
* for injected resources | |
* use in ORM/ODM entities? | |
* mild abuse? | |
* seems “ok” for required fields | |
* nullability | |
* var name String? = null vs var name String = “Bob Vance" | |
* !! operator | |
* platform types | |
* sometimes necessary after calls in to java methods | |
* smart casts | |
* useful after null checks | |
* type checks | |
* foo?.let { it.blah() } | |
* temp.kt | |
* functions | |
* default parameters — temp.kt | |
* named parameters | |
* parameter name changes | |
* binary compat | |
* source compile errors | |
* @JvmStatic | |
* @JvmOverloads | |
* classes | |
* com.antwerkz.critter.kotlin.KotlinClass | |
* single inheritance | |
* closed by default. to extend/override use open. | |
* override is a keyword. required. | |
* abstract | |
* constructors | |
* val/var in parameter declarations | |
* missing means not a field but can be used in init | |
* init {} | |
* calling primary | |
* see com.antwerkz.critter.test.criteria.PersonCriteria:25 | |
* lack of a primary | |
* javabot.model.Channel | |
* secondary constructors -- see KibbleImport below | |
* data — com.antwerkz.kibble.model.KibbleImport | |
* auto toString(), hashCode(), and equals() | |
* recommend for all properties to be val | |
* generated copy() | |
* each property is a parameter defaulted to this.foo | |
* annotation | |
* more or less “just” classes | |
* enum — com.antwerkz.kibble.model.Visibility | |
* companion object | |
* com.antwerkz.kibble.model.KibbleAnnotation | |
* "static methods" | |
* objects | |
* singleton | |
* Comparators | |
* filters | |
* anonymous instances | |
* com.antwerkz.test.SampleKibbleObject | |
* interfaces | |
* can have default functions — com.antwerkz.critter.Visible | |
* no default keyword necessary | |
* no state | |
* can declare properties | |
* implementors must provide a way to get that property | |
* functions part 2 | |
* varargs — Invoice.kt:44 | |
* vararg keyword not ... | |
* “spread operator” | |
* for expanding Lists/arrays in to vararg values | |
* extension functions | |
* can’t be overridden on subclasses (static resolution) | |
* com.antwerkz.critter.java.JavaClassTest#getMethods | |
* extension properties (below getMethods()) | |
* more of a facade than a real property | |
* no state | |
* use existing properties | |
* String.lastChar | |
* var StringBuilder.lastChar: Char | |
* get() = get(length() * 1) | |
* operators | |
* to() kotlin.TuplesKt#to | |
* delegation/composition -- Listogram | |
* flow control | |
* when com/antwerkz/bottlerocket/configuration/ConfigurationDocsTest.kt:35 | |
* an expression not a statement (return value) | |
* can use “constants” like Java or objects (e.g. Sets) | |
* no break necessary between cases | |
* multi*match cases | |
* can be called without parameters (no examples) | |
* useful for performance when any method calls for cases might be expensive to generate case classes | |
* for | |
* form: for x in foo ... | |
* com/antwerkz/bottlerocket/ReplicaSet.kt:34 | |
* for ( x in 1..100 step 2) | |
* ranges of anything Comparable | |
* only for inclusion checks not iterating | |
* exceptions | |
* try/catch/finally — com.antwerkz.bottlerocket.ReplicaSet.getPrimary | |
* treats all exceptions as unchecked | |
* can be used as an expression | |
* if (foo) { … } else throw SomeException() | |
* val foo = try { … } catch(…) { null } | |
* looping | |
* while/do*while — same as Java. *yawn* | |
* collections and streams | |
* uses standard Java Collections + extension functions | |
* no need for stream() | |
* most functions return List<T> | |
* arrayOf | |
* src/test/kotlin/com/antwerkz/bottlerocket/configuration/ConfigurationDocsTest.kt#78 | |
* listOf | |
* com.antwerkz.bottlerocket.MongoExecutable.getClient | |
* arrayListOf() * com.antwerkz.bottlerocket.MongoCluster.credentials | |
* mapOf | |
* com.antwerkz.bottlerocket.ReplicaSet.nodeMap | |
* map literals. kinda of. | |
* to — com.antwerkz.bottlerocket.BaseTest.testClusterWrites | |
* setOf | |
* hashSetOf | |
* linkedSetOf | |
* miscellany | |
* @JvmStatic | |
* DSLs | |
* com.antwerkz.bottlerocket.configuration.ConfigurationTest.Companion.COMPLEX_CONFIG — String example | |
* com.antwerkz.bottlerocket.configuration.ConfigurationTest.testBuilder — DSL example | |
* deprecations | |
* guided — kotlin.replaceAll | |
* WARNING is default and works as a normal deprecation: there will be warnings at call sites, and the IDE will strike it out, | |
* ERROR is the same, but a compilation error is reported instead of a warning, | |
* HIDDEN is what previously was @HiddenDeclaration: it simply makes this declaration invisible to clients at compile time. | |
* com.antwerkz.bottlerocket.MongoManager | |
---------------- | |
* Alternate targets | |
* Javascript | |
* deferred to after 1.0 | |
* Android | |
* Anko | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment