Dalinar
01/23/2019, 9:26 AM()
after the classname is not required...
2. however if you have secondary constructors then it is now required
3. and now you might also want to make that constructor privategildor
01/23/2019, 9:27 AMhho
01/23/2019, 9:28 AMgildor
01/23/2019, 9:28 AMconstructor
keyword for primary, if you want add annotation to primary constructor or add visibility modifier (what you also mentioned in 3)Dalinar
01/23/2019, 9:30 AM()
from after the classname, and then have secondary constructors then IDE will give me the error supertype initialization is imposssible without a primary constrctor.. so in this case the ()
is requiredprivate constructor
to avoid being able to call a no-args constructor?diesieben07
01/23/2019, 9:33 AMClassName()
()
are never optional.ClassName
refers to the companion object of the class.Dalinar
01/23/2019, 9:34 AM()
in the class declaration i mean - not invoking it - class Abc: Def()
vs class Abc(): Def()
Alowaniak
01/23/2019, 9:35 AMdiesieben07
01/23/2019, 9:35 AMDef()
in your first example) only works with primary constructor.Shawn
01/23/2019, 9:35 AMclass Abc()
isn’t invoking a constructor, it’s a redundant set of parens since your constructor is noargDalinar
01/23/2019, 9:36 AMdiesieben07
01/23/2019, 9:36 AMclass Abc() : Def()
is short for:
class Abc : Def {
constructor() : super() {
}
}
class Abc : Def {
// secondary constructors here
}
In that example Abc
is guaranteed to have one of it's secondary constructors called (since there is no primary one)Dalinar
01/23/2019, 9:40 AMhho
01/23/2019, 9:40 AMDico
01/23/2019, 9:41 AM()
in your class declaration and including a constructor
in the body removes the implicit no-arg constructor that would otherwise be present .