Need help in preparing presentation about Kotlin


#1

Hello, i'm preparing presentation about my attempt to convert my production project to Kotlin for Novosibirsk IT meetup and i have some questions, that i cannot identify is it bug or design my self.

  1. I cannot implement getter method with property. override modifier is illegal for custom getters, and without them compiler says that i have accidental override. Is it bug and will be fixed or by design? If by design - explain it please. Demo code
  2. I cannot access to values() method from enum's companion object, because it causes NPE, while in Java i can access to values() from class initializer. Is it bug and will be fixed or by design? If by design - explain it please. Kotlin demo code, Java demo code
  3. When I implement Kotlin's trait with Java class i should implement manually non-abstract methods from implemented trait. Is it bug and will be fixed or by design? If by design - explain it please. Kotlin demo code, Java demo code
  4. When I implement Kotlin's trait using delegation, then non abstract method from implemented traits are forwarded to delegate too, while i have expected, that they will be inherited. Is it bug and will be fixed or by design? If by design - explain it please. Demo code.

Also i cannot find information about current state of modules in Kotlin. Official documentation has links on them, but only information which i can find about them, is that they will not be implemented in 8th milestone.


#2
I cannot implement getter method with property. override modifier is illegal for custom getters, and without them compiler says that i have accidental override.

Not a bug, but a limitation that is unlikely to be removed. Properties and functions are different things and clashing JVM names (getId) do not mean that one is logically interchangeable with another.

I cannot access to values() method from enum's companion object, because it causes NPE, while in Java i can access to values() from class initializer.

A bug, please report to the tracker

When I implement Kotlin's trait with Java class i should implement manually non-abstract methods from implemented trait. Is it bug and will be fixed or by design?

Depends on the platform you are compiling for: we will support it for Java 8 and will not support it for Java 6 and 7.

When I implement Kotlin's trait using delegation, then non abstract method from implemented traits are forwarded to delegate too, while i have expected, that they will be inherited

This is by design, those non-abstract methods may be overridden, and their behavior has to be inherited, otherwise we'd get inconsistent behavior of the derived class.

Also i cannot find information about current state of modules in Kotlin

Modules are compile-time entities, pretty much mirror the IDE mosules that you see in the Project View.

If you have any further questions, feel free to ask.

Good luck with your presentation!


#3

Thanks for your answers, Andrey.

Properties and functions are different things and clashing JVM names (getId)
Could you please clarify it. As i know, in JVM there are no properties and they should be implemented with methods. Also i belive, that in Scala methods can be implemented with properties and vice versa and it's pretty handy feature
do not mean that one is logically interchangeable with another.

Yes, but why i can not write

val id = 1

override get() = $id To declare, that i intentionally want to implement method with this getter?

A bug, please report to the tracker


Reported: KT-7852
Modules are compile-time entities, pretty much mirror the IDE mosules that you see in the Project View.
I have tried to access to internal member of separate module in IDEA 141.1192.2 (Kotlin 0.11.91.4) and IDE/compiler are allowed me to do it. Does it mean, that modules support not implemented yet?
Good luck with your presentation!
Thanks:)

#4

I have remember one more questin. What is idiomatic equalent in Kotlin for following Java code:

InputStream stream = ...

byte[] block = new byte[2024];

while ((i = stream.read(block)) > 0) {
    out.write(block, 0, i);
}

And what is the motivation to not make assignments expressions?


#5

Could you please clarify it. As i know, in JVM there are no properties and they should be implemented with methods. Also i belive, that in Scala methods can be implemented with properties and vice versa and it's pretty handy feature

It's not a matter of how JVM sees it, but how the language does. In Scala you can override a def by a val, but not vice versa, in Kotlin this is not the case.

I have tried to access to internal member of separate module in IDEA 141.1192.2 (Kotlin 0.11.91.4) and IDE/compiler are allowed me to do it. Does it mean, that modules support not implemented yet?

The corresponding error messages are not implemented, the modules themselves (as units of dependency management) are.

I have remember one more questin. What is idiomatic equalent in Kotlin for following Java code:

You can use standard library IO utilities for reading from/writing to streams