Created
December 9, 2017 16:56
-
-
Save geraldcroes/6ffa82303b3f04850321e3c8467c9e64 to your computer and use it in GitHub Desktop.
Embedded companion object in an interface
This file contains hidden or 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
| interface FileParser { | |
| companion object { | |
| fun createFromFileName(fileName: String) = | |
| when (fileName.substringAfterLast('.')) { | |
| "xml" -> XmlFileParser() | |
| "json" -> JsonFileParser() | |
| else -> throw Exception("I don't know how to deal with $fileName.") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment