While working with Kotlin, I see you can define methods in a Kotlin file that has no class or object type (i.e. a file without class Test
or object Test
). I also see when you put methods into a Kotlin file without the class
or object
keywords, you need to import the method (i.e. import com.package.testMethod
) to the file you want to use it. A little more context, I was trying to make some utility methods and started tinkering with both object
and kotlin file with no class/object
My question is what is the use case for having a methods that aren't in some kind of object
file? And when would you want to use this over something like object
?