Quantcast
Channel: Kotlin: 'val' on secondary constructor parameter is not allowed - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by s1m0nw1 for Kotlin: 'val' on secondary constructor parameter is not allowed

$
0
0

In addition to the great answer of yole, the documentation is pretty clear as well:

Note that parameters of the primary constructor can be used in the initializer blocks. They can also be used in property initializers declared in the class body. [...] In fact, for declaring properties and initializing them from the primary constructor, Kotlin has a concise syntax:

class Person(val firstName: String, val lastName: String, var age: Int) {    // ...}

Much the same way as regular properties, the properties declared in the primary constructor can be mutable (var) or read-only (val).

This all does not apply to secondary constructors.


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>