Kotlin 1.2 Beta released

Beta version of Kotlin 1.2 available now with some new interesting features
03 October 2017   2928

Good news for all Kotlin enthusiasts and Android developers. New Beta version of Kotlin was recently released.

What's new in Kotlin 1.2 Beta?

According to the developers, the major feature of version 1.2 is experimental support for multiplatform projects. Additionally, the language and standard library are now feature complete – all the new features planned for Kotlin 1.2 have been implemented.

In terms of tooling, Kotlin 1.2 Beta includes the same set of features as the recently released 1.1.50 update. The beta is compatible with all versions of IntelliJ IDEA from 2016.3 until 2017.3, as well as with Android Studio 2.3 and 3.0.

So, let's check the most interesting changes

Multiplatform projects

Multiplatform projects are a new experimental feature in Kotlin 1.2, that allows you to reuse code between target platforms supported by Kotlin – JVM, JavaScript and (in the future) Native. In a multiplatform project, you put code which is shared between platforms into a common module, and platform-dependent parts into platform-specific modules that depend on it. When you compile such a project for a specific platform, the code for both the common and platform-specific parts is generated.

A key feature of the multiplatform project support is the possibility to express dependencies of common code on platform-specific parts through expected and actual declarations. An expected declaration specifies an API (class, interface, annotation, top-level declaration etc.). An actual declaration is either a platform-dependent implementation of the API or a typealias referring to an existing implementation of the API in an external library:

// Common code
expect fun hello(world: String)
 
expect class URL(spec: String) {
  open fun getHost(): String
  open fun getPath(): String
}
 
// JVM code
actual fun hello(world: String) {
  println("Hello JVM $world")
}
 
actual typealias URL = java.net.URL

Array Literals in Annotations

A new language feature in Kotlin 1.2 is the support for array literals in annotations. Now, instead of writing something like @CacheConfig(cacheNames = arrayOf("books", "default")), you can simply use a literal expression:

@CacheConfig(cacheNames = ["books", "default"])

lateinit improvements

Developers added a new reflection API allowing you to check whether a lateinit variable has been initialized:

lateinit var file: File
 
// ...
 
if (::file.isInitialized) {
  ...
}

Bound callable reference improvements

You can now omit this in expressions like this::foo, which create callable references bound to a member of this. Instead, you can simply write ::foo. Previously the syntax with the empty left side could only be used to create callable references to top-level declarations. 

Type inference improvements

The Kotlin compiler can now use information from type casts in type inference. If you’re calling a generic method that returns a type parameter T and casting the return value to a specific type Foo, the compiler now understands that T for this call needs to be bound to the type Foo. This is particularly important for Android developers, because the compiler can now correctly analyze findViewById calls in Android API level 26:

val button = findViewById(R.id.button) as Button

As the method has been changed to <T extends View> T findViewById(int id), Kotlin 1.1 was unable to infer the type argument for T in such calls.

Warnings as errors

The compiler now provides an option to treat all warnings as errors. Use -Werror on the command line, or the following Gradle snippet:

compileKotlin {
  kotlinOptions.warningsAsErrors = true
}

Smart cast improvements

Smart casts are now applied to subjects of safe casts:

fun foo(x: Foo?) {
  val b = (x as? SubClass)?.subclassMethod1()
  if (b != null) {
    x.subclassMethod2() // x is smart cast to SubClass
  }
}

Also, smart casts in a lambda are now allowed for var variables that are only modified before the lambda:

var x: String? = null
if (flag) x = "Yahoo!"
 
run {
  if (x != null) {
    println(x.length) // x is smart cast to String
  }
}

kotlin.math

kotlin.math is a new package in the Kotlin 1.2 standard library, allowing you to perform mathematical operations in cross-platform code. In 1.2-Beta, we made several improvements to it:

  • Inverse hyperbolic functions (asinhacoshatanh) are now supported
  • Functions related to binary representation of floating point numbers (toBitsnextUp and so on), are now available for JavaScript
  • Improved precision of math polyfills for JavaScript

How to do try Kotlin 1.2 Beta?

In Maven/Gradle: Add http://dl.bintray.com/kotlin/kotlin-eap-1.2 as a repository for the build script and your projects; use 1.2.0-beta-31 as the version number for the compiler plugin and the standard library.

In IntelliJ IDEA: Go to Tools → Kotlin → Configure Kotlin Plugin Updates, then select “Early Access Preview 1.2” in the Update channel drop-down list, then press Check for updates.
The command-line compiler can be downloaded from the GitHub release page.

On try.kotlinlang.org: Use the drop-down list at the bottom-right corner to change the compiler version to 1.2‑Beta (coming soon).

Learn more at official blog.

Firefox Preview to Get Add-Ons Support

This is the new mobile browser that is based on the GeckoView engine and the Mozilla Android Components library set
06 February 2020   235

Mozilla developers have added support for add-ons to the codebase of the Firefox Preview mobile browser (Fenix), which is being developed to replace the Firefox edition for the Android platform. The new browser is based on the GeckoView engine and the Mozilla Android Components library set.

The ability to connect add-ons based on the WebExtension API is available for testing in the nightly builds of Firefox Preview. The item "Add-ons Manager" appeared in the menu, which shows the add-ons available for installation. In its current form, only uBlock Origin is present in the list of add-ons compatible with Firefox Preview. Support for other add-ons is expected later.

Get more at the official blog.