- Kotlin 2
596 :デフォルトの名無しさん[sage]:2018/02/17(土) 00:19:37.32 ID:1ji1uAN3 - >>594
でも、空のプライマリコンストラクタを明示的に宣言するのと省略するのでは厳密には同一ではないですよね?? だから、言葉の定義の問題にもなっちゃうけど、initブロックはinitブロックであってプライマリコンストラクタと同一視 しない方がいいとか。プライマリコンストラクタはあくまでclass Test(val p1: String)のval p1: String部分だけで、 プライマリコンストラクタはボディは持てない。 初期化はinitブロックで行うとか?
|
- Kotlin 2
597 :デフォルトの名無しさん[sage]:2018/02/17(土) 00:24:21.47 ID:1ji1uAN3 - https://kotlinlang.org/docs/reference/classes.html
正式な言語仕様書とかないんでしったけ?? JavaとかC#はしっかりした言語仕様書みたいのあって言葉もしっかり定義されてると 思いますが、kotlinはそういうのないとか・・
|
- Kotlin 2
598 :デフォルトの名無しさん[sage]:2018/02/17(土) 00:37:46.91 ID:1ji1uAN3 - Note that code in initializer blocks effectively becomes part of the primary constructor.
Delegation to the primary constructor happens as the first statement of a secondary constructor, so the code in all initializer blocks is executed before the secondary constructor body まぁ、ここにはプライマリコンストラクタの一部になるって書いてあるね。
|