简体   繁体   中英

How to access class level variables from inner object class in kotlin

I am using branchSDK, It creates Object class inside the activity lcass. I need to access class level variables from this object class.

Following the inner object class, that branch created.

 object branchListener : Branch.BranchReferralInitListener {
        override fun onInitFinished(referringParams: JSONObject?, error: BranchError?) {
            if (error == null) {
                Log.i("BRANCH_SDK", referringParams.toString())

                if(referringParams?.has("news") ==true){

                }

            } else {
                Log.e("BRANCH_SDK", error.message)
            }
        }
    }

I don't use Branch. From looking at their basic instructions here that are written in Java, the equivalent would be an anonymous object assigned to a property, which does have access to the outer class members:

val branchListener = object: Branch.BranchReferralInitListener {
    override fun onInitFinished(referringParams: JSONObject?, error: BranchError?) {
        if (error == null) {
            Log.i("BRANCH_SDK", referringParams.toString())

            if(referringParams?.has("news") == true){

            }

        } else {
            Log.e("BRANCH_SDK", error.message)
        }
    }
}

Presumably there is some function this listener can be passed to when you're making some kind of request, but it wasn't mentioned on this (the only page I read from their instructions).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM