How to organize Kotlin extension methods

As far as I am concerned, you should put them into a utility file, as you did in Java code base before.

But mention, you no longer need to put them into a class. Top-level functions are the best choice.

You can refer to the kotlin standard library or some open source projects like anko, those would be good examples.

In my case, I put extensions of one class into a file which have the same name of the original file in another package, and use

@JvmMultifileClass

to reduce the number of generated class files.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)