Antoine Gagnon
04/22/2020, 8:52 PMclass Dog{
val name:String
val age:Int
init { this = fetchDogFromSomewhere() }
}
fun fetchDogFromSomewhere():Dog{
// Things
}
Is there some way to achieve this? Right now I’m using a companion method that calls fetchDogFromSomwhereShawn
04/22/2020, 9:02 PMShawn
04/22/2020, 9:03 PMthis
Shawn
04/22/2020, 9:04 PMDog
and you’d like for folks to receive the same instance if they try to instantiate one?Casey Brooks
04/22/2020, 9:08 PMCasey Brooks
04/22/2020, 9:09 PMoperator fun invoke()
in the companion object, which is about as good as you could get https://pl.kotl.in/EV4wuPggtShawn
04/22/2020, 9:12 PMinvoke
or give it a more descriptive name is up to youJakub Pi
04/22/2020, 9:54 PM