Skip to content

Instantly share code, notes, and snippets.

@praveenKajla
Last active September 5, 2017 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save praveenKajla/366fc0e2252d5e67d28ad285c92a0391 to your computer and use it in GitHub Desktop.
Save praveenKajla/366fc0e2252d5e67d28ad285c92a0391 to your computer and use it in GitHub Desktop.
class Log(){
companion object Factory{
@JvmStatic fun createFileLog(filename: String):Log = Log(filename)
//we can access this static function from java using @JvmStatic as Log.createFileLog("File.txt")
}
//second companion object not possible
constructor(filename:String):this(){}
//fun usingFactoryFunction(){
// Factory.createFileLog("random")
//}
//we can access inside member function
}
fun main(args: Array<String>) {
val log = Log()
//val fileLog = Log.Factory.createFileLog("File.txt")
val fileLog = Log.createFileLog("File.txt")//using companion keyword
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment