📜 ⬆️ ⬇️

Kotlin M5 released

Soon the year we opened the source code Kotlin . During this time, a lot of work has been done, in which both the developers from JetBrains and representatives of the community actively participated. We received 164 pull requests , that is, something about one patch every two days.

Today we released another milestone: Kotlin M5 . This post gives a brief description of the changes included in the M5.

Default constructors


')
A class written in Kotlin can have only one constructor. There is no need to overload constructors, since there are default values ​​for parameters:

class Foo(val bar: Int = 0) 


However, many Java frameworks, such as JAXB, require the class to have a default constructor, that is, no parameters. Now Kotlin generates such a constructor, if all parameters can be omitted.

Inner Classes



Starting with M5, Kotlin supports not only inner-classes, but also “static” nested-classes. Since an inner-class object stores a reference to an object of an enclosing class, which can lead to unexpected consequences (for example, memory leaks), Kotlin requires explicitly marking the inner-classes with a corresponding annotation:

 class Outer { val foo = 1 inner class Inner { val bar = foo + 1 } } 


Generics, Nullability, Assertions



Kotlin distinguishes between nullable and not-null references at the type system level. Since there are no guarantees for references in Java that they are not null, Kotlin loads all non-primitive types as nullable. For example, the Java method foo(ArrayList) Kotlin foo(ArrayList<String?>?) , null, . , : - Kotlin ArrayList, foo(), ArrayList , . , : Kotlin generic- nullable, foo() foo(ArrayList?) .

Java- "" Kotlin, NPE, Kotlin , : - , Java- Kotlin-:

Exception in thread "main" java.lang.IllegalStateException: Method specified as non-null returned null: JavaClass.foo at _DefaultPackage.main(hello.kt:4)



Kotlin M5 , IntelliJ IDEA 12.0.3 .

, : Darcula . M5 (-). !
foo(ArrayList) Kotlin foo(ArrayList<String?>?) , null, . , : - Kotlin ArrayList, foo(), ArrayList , . , : Kotlin generic- nullable, foo() foo(ArrayList?) .

Java- "" Kotlin, NPE, Kotlin , : - , Java- Kotlin-:

Exception in thread "main" java.lang.IllegalStateException: Method specified as non-null returned null: JavaClass.foo at _DefaultPackage.main(hello.kt:4)



Kotlin M5 , IntelliJ IDEA 12.0.3 .

, : Darcula . M5 (-). !
 foo(ArrayList)  Kotlin   foo(ArrayList<String?>?) ,        null,     .    ,      :  -  Kotlin     ArrayList,       foo(),    ArrayList ,    .     ,     :  Kotlin    generic- nullable,   foo()    foo(ArrayList?)        . 

Java- "" Kotlin, NPE, Kotlin , : - , Java- Kotlin-:

Exception in thread "main" java.lang.IllegalStateException: Method specified as non-null returned null: JavaClass.foo at _DefaultPackage.main(hello.kt:4)



Kotlin M5 , IntelliJ IDEA 12.0.3 .

, : Darcula . M5 (-). !
foo(ArrayList) Kotlin foo(ArrayList<String?>?) , null, . , : - Kotlin ArrayList, foo(), ArrayList , . , : Kotlin generic- nullable, foo() foo(ArrayList?) .

Java- "" Kotlin, NPE, Kotlin , : - , Java- Kotlin-:

Exception in thread "main" java.lang.IllegalStateException: Method specified as non-null returned null: JavaClass.foo at _DefaultPackage.main(hello.kt:4)



Kotlin M5 , IntelliJ IDEA 12.0.3 .

, : Darcula . M5 (-). !

foo(ArrayList) Kotlin foo(ArrayList<String?>?) , null, . , : - Kotlin ArrayList, foo(), ArrayList , . , : Kotlin generic- nullable, foo() foo(ArrayList?) .

Java- "" Kotlin, NPE, Kotlin , : - , Java- Kotlin-:

Exception in thread "main" java.lang.IllegalStateException: Method specified as non-null returned null: JavaClass.foo at _DefaultPackage.main(hello.kt:4)



Kotlin M5 , IntelliJ IDEA 12.0.3 .

, : Darcula . M5 (-). !

foo(ArrayList) Kotlin foo(ArrayList<String?>?) , null, . , : - Kotlin ArrayList, foo(), ArrayList , . , : Kotlin generic- nullable, foo() foo(ArrayList?) .

Java- "" Kotlin, NPE, Kotlin , : - , Java- Kotlin-:

Exception in thread "main" java.lang.IllegalStateException: Method specified as non-null returned null: JavaClass.foo at _DefaultPackage.main(hello.kt:4)



Kotlin M5 , IntelliJ IDEA 12.0.3 .

, : Darcula . M5 (-). !

Source: https://habr.com/ru/post/168265/


All Articles