Last active
June 17, 2017 10:13
-
-
Save shubhra02/847edf7f9bbfc73693a4755ef3ffcc96 to your computer and use it in GitHub Desktop.
Type Safe Code
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
import com.typesafe.config._ | |
case class Employee(config: Config) { | |
val jobTitle = config.getString("jobTitle") | |
object company { | |
val companyName = config.getString("company.companyName") | |
val place = config.getString("company.place") | |
} | |
} | |
val config = ConfigFactory.parseString( | |
""" | |
|se.typesafe.example { | |
| jobTitle = "Software consultant" | |
| company { | |
| companyName = "Knoldus" | |
| place = "Noida" | |
| } | |
|} | |
""".stripMargin | |
) | |
val employee = Employee(config.getConfig("se.typesafe.example")) | |
employee.jobTitle | |
// res0: String = Software consultant | |
employee.company.companyName | |
// res1: String = Knoldus | |
employee.company.place | |
// res2: String = Noida |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment