There are no parens, because it's not creating an instance of outer
.
If nestedclass
were an inner class, then each instance would be associated with an instance of outer
, so you'd need to construct the latter before the former. (And you could do that by adding the parens, as outer().nestedclass()
.)
But it's only a nested class — defined within the lexical scope of outer
, but not associated with an instance. So outer.nestedclass
is simply the class name, and you can call its constructor directly as outer.nestedclass()
.
So the line:
println(outer.nestedclass().description)
constructs an instance of outer.nestedclass
, gets the value of its description
property, and prints that out.
(If you know Java, there are two big differences to mention. First, in Java inner classes are the default, and you need to specify static
to make them nested; but in Kotlin, nested classes are the default, and there's an inner
keyword. And second, Kotlin doesn't have Java's new
keyword to indicate a constructor call, so it can be harder to spot them.)
(Also, as Tenfour04 says, it's conventional to start class names with a capital letter, AKA PascalCase. That makes them much easier to distinguish from method names and other identifiers — which are conventionally in camelCase. This question is one situation in which the extra clarity would help.)