I'm continuing a question from yesterday since I h...
# getting-started
w
I'm continuing a question from yesterday since I haven't quite nailed it down yet. It should be quite simple though. I'm trying to do the Kotlin version of this Java:
Copy code
class MyClass {
    Context context;

    MyClass(Context context) {
        this.context = context.getApplicationContext();
    }
}
The key point is that I want to make sure that I don't hold a reference to the
Context
that's passed in, but rather hold a reference to the
context.getApplicationContext()
. I've tried this attached picture in Kotlin, though as you can see it still refers to and holds onto the
Context
that was passed in (MainActivity) which is very much what I don't want. I've also done this successfully
Copy code
class MyClass private constructor(val context : Context) {
    companion object {
        fun create(context: Context) = MyClass(context.applicationContext)
    }
}
though it's not ideal since if I call it from Java I have to refer to the companion object with
MyClass.Companion.create(context)
where ideally I'd just call the constructor just like with the Java example