Paul N
06/11/2019, 8:03 PMval baseURL = "http://$domainName/endpoint"
and then a function like this
fun someMore(domainName : String, somethingElse : String) {
val x = "$baseURL$somethingElse
}
then x should equal http://mydomainname/endpoint/mysomethingElse if I pass in mydomainname and mysomethingelse to the function ?LeoColman
06/11/2019, 8:03 PMval baseUrl by lazy { "http://$domainName/endpoint" }
"foo".format(..)
Paul N
06/11/2019, 8:05 PMstreetsofboston
06/11/2019, 8:30 PMval baseURL get() = "http://$domainName/endpoint"
Only when called/used the string will be evaluated.pniederw
06/11/2019, 11:27 PM$domainName
will be resolved in the original class scope rather than in function scope. One solution I can think of is to turn baseURL
into a lambda that accepts domainName
as parameter.Paul N
06/12/2019, 8:42 AMMike
06/12/2019, 12:28 PMsomeMore
is called more than once, with a different domainName
, you won’t get the result you want as baseURL will always return the first value.
If someMore IS only called once, then there’s likely a cleaner way to set the domainName
in baseURL.Stefan Beyer
06/12/2019, 2:18 PMfun baseURL(domainName: String) =
"http://$domainName/endpoint"
fun someMore(domainName: String, somethingElse: String) {
val x = "${baseURL(domainName)}$somethingElse"
}