Appendix B. Kotlin Cheat Sheet
This is a handy reference for Java developers who need to make a quick connection with Kotlin without having to spend time taking a full Kotlin course. Since Corda is written in Kotlin, exposure to some Kotlin code will occur, especially when debugging and digging through StackOverflow and the Corda source code. Additional Kotlin material is available at http://masteringcorda.com.
Key Kotlin Points
-
Kotlin does away with the semicolon at the end of a line of code.
-
The main method looks like this instead:
funmain(args:Array<String>){NodeStartupCli().start(args)} -
A Kotlin file can have multiple class definitions. For example, the MerkleTransaction.kt file in Corda has the following declarations:
abstractclassTraversableTransaction..classFilteredTransaction..dataclassFilteredComponentGroup..classComponentVisibilityExceptionclassFilteredTransactionVerificationException -
Class names can be implied. In the following code, the class name will be generated by Kotlin during compilation:
// This class is used by the smoke tests as a check that the node module// isn't on their classpath@file:JvmName("Corda")packagenet.corda.nodeimportnet.corda.cliutils.startimportnet.corda.node.internal.NodeStartupClifunmain(args:Array<String>){// Pass the arguments to the Node factory. In the Enterprise// edition, this line is modified to point to a subclass. It// will exit the process in case of startup failure and is not// intended ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access