4
cb219
6d

"Learning" kotlin for android dev has been a wild ride yet. Kotlin is kinda cool, a mix between python and Java but with many nice features. Then again there are kotlin features on which I just scratch my head like data classes and companion objects.
And then for android (not kotlin specific) I see things like calling Timepicker(...) or Timepicker Dialog(...) without assigning it to a variable and wonder how that can even work. Can someone explain? There's no creation method, static method or anything?
I feel like a competent and incompetent dev at the same time.

Comments
  • 0
    Do you mind giving example code?
  • 1
    @sbiewald my code is quite small. I have a button click listener. Inside this listener I init some Calendar settings and then call TimePickerDialog(this,this,...).show() ... no "var tpd = TimePickerDialog(...)" or so
    The code works fine. I've just never seen this kind of initialization. I know examples like someList.add(new Whatever(...)) but TimePicker is just confusing to me.
  • 0
    @cb219 You call the constructor and on the created object you call the method show().
    It is automatically detected how long the object is required, so a variable is not needed here.

    The same would work in Java and Python btw. :)
Add Comment