回答編集履歴

5

修正

2023/12/15 07:49

投稿

jimbe
jimbe

スコア12698

test CHANGED
@@ -23,4 +23,4 @@
23
23
  ```
24
24
  object B
25
25
  ```
26
- でも良いのは・・・
26
+ のは・・・"的"じゃなくて本当になってしまうのでダメでしょうね x_x

4

リンク追加

2023/12/15 07:43

投稿

jimbe
jimbe

スコア12698

test CHANGED
@@ -1,3 +1,12 @@
1
+ この問題(?)は前から言われているようですね。
2
+
3
+ Kotlin Discussions
4
+ [How can I make nested class constructors accessible only by surrounding class?](https://discuss.kotlinlang.org/t/how-can-i-make-nested-class-constructors-accessible-only-by-surrounding-class/12608)
5
+
6
+ Stack Overflow
7
+ [How to create an inner class where only the outer class can access the constructor, but the rest is visible everywhere?](https://stackoverflow.com/questions/54220934/how-to-create-an-inner-class-where-only-the-outer-class-can-access-the-construct)
8
+
9
+
1
10
  試していたのですが、クラス B をシングルトン的に…ということなら
2
11
  ```kotlin
3
12
  fun main(args: Array<String>) {

3

不要行削除

2023/12/15 06:56

投稿

jimbe
jimbe

スコア12698

test CHANGED
@@ -1,7 +1,6 @@
1
1
  試していたのですが、クラス B をシングルトン的に…ということなら
2
2
  ```kotlin
3
3
  fun main(args: Array<String>) {
4
- var a = A()
5
4
  var b = A.B
6
5
  b.print()
7
6
  }

2

微修正

2023/12/15 06:49

投稿

jimbe
jimbe

スコア12698

test CHANGED
@@ -11,7 +11,7 @@
11
11
  }
12
12
  }
13
13
  ```
14
- 実行結果
14
+ 実行結果(paiza.IO)
15
15
  ```
16
16
  object B
17
17
  ```

1

kotlin的に笑

2023/12/15 06:47

投稿

jimbe
jimbe

スコア12698

test CHANGED
@@ -7,12 +7,12 @@
7
7
  }
8
8
  class A() {
9
9
  object B {
10
- fun print() { println("class B?") }
10
+ fun print() = println("object B")
11
11
  }
12
12
  }
13
13
  ```
14
14
  実行結果
15
15
  ```
16
- class B?
16
+ object B
17
17
  ```
18
18
  でも良いのでは・・・。