How Kotlin Changed JVM-Based Languages.

This was originally going to be a guest post on Forbes, before I realized they weren’t accepting guest posts anymore. Oh well!

Kotlin is a cool programming language. While there are many disadvantages, such as having an elegant syntax yet having a huge learning curve), there are also many advantages. The surprisingly simple syntax is one thing, with fun instead of public static void, whatever in Java. But let me tell you about something pretty interesting.

Java has explicitly-typed object definitions. What I mean by that is:

  • void is mainly used as the return types for the main method in a program.
  • You can only make variables with a certain type (think int, boolean, etc.). But in Kotlin, things get very interesting. It’s actually almost like JavaScript:
  • "val" defines a certain value.
  • var defines a value that can be changed, like you can increment a var by using x += 1

See the difference? But, one thing is: Kotlin actually does have explicit typing, we just don’t need to use it (for only variable definitions). Look at this valid Kotlin code:

fun difference(a: Int, b: Int) : Int {
        return a + b;
}

Yeah, but if you want to use it in var definitions:

var a: Int = 0

This means you can validly use explicit typing if you want to.

Now how does this "change jvm-based programming languages?" Kotlin is mainstream in both Android and some Java development. Even Android is trying to phase out Java in their development. Kotlin has automatic type inference when compiled. Even though it causes slower compilation, Kotlin does automatically match up your variable with the type it’s supposed to be, as long as it doesn’t have explicit type definitions (which makes it faster). Everything is automatically casted to the required type. If you really need to do explicit casting, the as operator is there for you.

Kotlin is there for you, even though it’s pretty hard to learn. It has very concise syntax, but it has has slow type inference when you need to declare a variable. Explicit type definitions cause faster compilation time, as Kotlin doesn’t need to find the required type.

Alright, peace out.
- acaiberii