Last active
September 5, 2017 07:05
-
-
Save praveenKajla/366fc0e2252d5e67d28ad285c92a0391 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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