Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Kotlin
class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    private val myName:MyName = MyName("Kotlin noob")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
        binding.myName = myName //line 1
        binding.doneButton.setOnClickListener {
            addName(it)
        }
    }


    fun addName(view: View) {

        myName?.nickName = nickName_edit.text.toString() //line 2
        binding.showNameTextView.text = "hello ${binding.enterNameEditText.text}"
        binding.showNameTextView.visibility = View.VISIBLE
        binding.enterNameEditText.visibility = View.GONE
        view.visibility = View.GONE
    }

//this is the class used for data 
data class MyName(var name:String="", var nickName:String="")
}




how the commented code work ? i mean in line 1 how are we assigning myName to myName they are the same thing, and how we can assign reference variables to each ?
and in line 2 what is that ? after myName


* i came from a Java background so it be nice if you can explain it with Java example/syntax

What I have tried:

i did some research but it's still ambiguous.
Posted
Updated 17-Jul-19 1:52am
v3
Comments
Richard MacCutchan 17-Jul-19 4:01am    
How about studying kotlin to find out?
hiwa doski 3-Aug-19 15:10pm    
how about giving me a simple answer?
Richard MacCutchan 4-Aug-19 4:53am    
I already did; if you want to make it as a developer then you need to study the language.
hiwa doski 4-Aug-19 5:11am    
i got the answer from other people which was a simple thing and i understood very quickly and i didn't had to study the whole Kotlin language to understand a simple thing.
Richard MacCutchan 4-Aug-19 5:18am    
So what are you going to do next time you come across something you do not understand? Trying to learn a language by posting questions on tech forums is a waste of time.

1 solution

@Richard-MacCutchan presents a compelling argument - study Kotlin so you can find out what the code does. See Kotlin for Android - Kotlin Programming Language[^]

Debugging is usually an excellent way of finding out what code does too - see Debugging - Kotlin Programming Language[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900