Skip to content

Commit 1d22f52

Browse files
committed
Add private constructors example
1 parent eb57925 commit 1d22f52

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

content/binary-api.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,19 @@ Related to discussion in [https://github.com/lightbend/mima/discussions/724](htt
4848

4949
### No way to inline reference to private constructors
5050

51-
It is currently impossible to refer to private constructors in inline methods. If users want to access one of those, they must write an accessor explicitly. This extra indirection is undesirable.
51+
It is currently impossible to refer to private constructors in inline methods.
52+
```scala
53+
class C private()
54+
object C:
55+
inline def newC: C = new C() // Implementation restriction: cannot use private constructors in inline methods
56+
```
57+
If users want to access one of those, they must write an accessor explicitly. This extra indirection is undesirable.
58+
```scala
59+
class C private()
60+
object C:
61+
private def newCInternal: C = new C()
62+
inline def newC: C = newCInternal
63+
```
5264

5365
## Proposed solution
5466

0 commit comments

Comments
 (0)