Posts

Showing posts with the label Kotlin

Kotlin Interop guide

Interop guide A set of rules for authoring public APIs in Java and Kotlin with the intent that the code will feel idiomatic when consumed from the other language. Last update: 2017-11-02 Java (for Kotlin consumption) No hard keywords Do not use Kotlin’s  hard keywords  as the name of methods or fields. These require the use of backticks to escape when calling from Kotlin.  Soft keywords ,  modifier keywords , and  special identifiers  are allowed. For example, Mockito’s  when  function requires backticks when used from Kotlin: val callable = Mockito . mock ( Callable :: class . java ) Mockito . `when` ( callable . call ()). thenReturn ( /* … */ ) Lambda parameters last Parameter types eligible for  SAM conversion  should be last. For example, RxJava 2’s  Flowable.create()  method signature is defined as: public static < T > Flowable < T > create ( FlowableOnSubscribe < T ...

Kotlin Style guide

Style guide This document serves as the complete definition of Google’s Android coding standards for source code in the Kotlin Programming Language. A Kotlin source file is described as being in Google Android Style if and only if it adheres to the rules herein. Like other programming style guides, the issues covered span not only aesthetic issues of formatting, but other types of conventions or coding standards as well. However, this document focuses primarily on the hard-and-fast rules that we follow universally, and avoids giving advice that isn’t clearly enforceable (whether by human or tool). Last update: 2017-11-02 Source files All source files must be encoded as UTF-8. Naming If a source file contains only a single top-level class, the file name should reflect the case-sensitive name plus the  .kt  extension. Otherwise, if a source file contains multiple top-level declarations, choose a name the describes the contents of the file, apply PascalCase, and ap...