Java static methods in Kotlin

 The best way to represent a static Java method in Kotlin
11 September 2017   1901

You can place the function in the "companion object"

So the java code like this:

class Foo { public static int a() { return 1; } }

will become

class Foo { companion object { fun a() : Int = 1 } }

What is Companion Objects?

An object declaration inside a class can be marked with the companion keyword:

class MyClass {
   companion object Factory {
       fun create(): MyClass = MyClass()
   }
}

Members of the companion object can be called by using simply the class name as the qualifier:

val instance = MyClass.create()

However, on the JVM you can have members of companion objects generated as real static methods and fields, if you use the @JvmStatic annotation. See the Java interoperability section for more details.

JetBrains to Roll Out Ktor Framework

Framework is suitable for writing back-end projects and microservices in the Kotlin language
20 November 2018   194

JetBrains developers told about the release of the stable version of the Ktor 1.0 framework. It helps to create asynchronous servers and clients in related systems. According to the creators, the framework is suitable for writing back-end projects and microservices in the Kotlin language. Documentation and project generator are published on the official website.

First of all, it is worth noting that this is an open source project that is distributed under the Apache 2 license. The main components are:

  • HTTP server running on a virtual machine. It works on Netty, Jetty, and server-side Java programs. It can be placed in a container, embedded in desktop or Android applications, as well as run on Tomcat. Moreover, it corresponds to the paradigm of the application of twelve factors.
  • Multiplatform HTTP client. Although asynchronous, it uses the same coroutines and I / O elements that control the server.

Tools will help the developer to customize the main components of the application.

The Kotlin / Native project supports Ktor, starting with version 0.8. In this case, the working version of Kotlin / Native 0.9 was released in early September 2018. In it, developers added support for unsigned types and interoperability with C, Objective-C / Swift.