Kotlin generated class file out of .kt is bigger than .java file


#1

I have simple static POJO in java got converted in to Kotlin. The kotlin generated class file size is twice bigger than the java generated class file. I am using jdk1.8. Any reasons?


#2

One of the possible reasons is that Kotlin stores additional metadata about the class in special annotations. They increase the size of the class file but do not affect runtime performance.

Also, if you marked the class as data, Kotlin generates a number of additional methods such as copy() which will also increase the size of the class file.

To see exactly what is contained in the class file, you can use the Tools | Kotlin | Show Kotlin Bytecode action.


#3

Thanks Yole. I could see lot of extra code being generated as part of Kotlin Byte Code. Doesn’t it bump-up the size of the .jar file in case of bigger projects?


#4

Which code do you mean exactly, and why do you think this is a problem?