В чем разница между классом и конструктором ⇐ Android
-
Anonymous
В чем разница между классом и конструктором
I am currently going through the android basics with compose course and I'm learning about classes. I had trouble understanding what a constructor, I don't know what's a constructor or why is it used and I don't really understand secondary constructors. But at least I know that the primary constructor is the same thing as the class declaration (correct me if I'am wrong), so whenever I declare a class I am declaring a primary constructor.
Now I am learning modifiers and for some reason that I don't understand, the syntax for constructors is: class Name modifier constructor () but for classes it's: modifier class Name()
So I think that my idea about a class being the same as a primary constructor is wrong? If so, what's the difference?
open class SmartDevice protected constructor (val name: String, val category: String) { ... } internal open class SmartDevice(val name: String, val category: String) { ... } These are code snippets from the course, why is the first one considered a constructor and the second one a class? Thank you for reading and sorry if it seems too basic.
Источник: https://stackoverflow.com/questions/781 ... onstructor
I am currently going through the android basics with compose course and I'm learning about classes. I had trouble understanding what a constructor, I don't know what's a constructor or why is it used and I don't really understand secondary constructors. But at least I know that the primary constructor is the same thing as the class declaration (correct me if I'am wrong), so whenever I declare a class I am declaring a primary constructor.
Now I am learning modifiers and for some reason that I don't understand, the syntax for constructors is: class Name modifier constructor () but for classes it's: modifier class Name()
So I think that my idea about a class being the same as a primary constructor is wrong? If so, what's the difference?
open class SmartDevice protected constructor (val name: String, val category: String) { ... } internal open class SmartDevice(val name: String, val category: String) { ... } These are code snippets from the course, why is the first one considered a constructor and the second one a class? Thank you for reading and sorry if it seems too basic.
Источник: https://stackoverflow.com/questions/781 ... onstructor
Мобильная версия