Miguel Vargas
11/18/2021, 8:05 PMpackage a
class B {
// only accessible from within this file
file-private val priv = 123
}
fun c(b: B) {
println("I can access ${b.priv}")
}Miguel Vargas
11/18/2021, 8:09 PMjw
11/18/2021, 9:32 PMjw
11/18/2021, 9:33 PMfileprivate, and visually I like it better due to lack of hyphen. Also not sure if the hyphen would introducer parser ambiguities or not.louiscad
11/18/2021, 10:46 PMjw
11/19/2021, 12:14 AMMiguel Vargas
11/19/2021, 12:34 AMfileprivate also follows existing compound keyword convention such as typealiasBen Woodworth
11/19/2021, 5:38 AMprivate@file?
Extend this notation to target specific types to also be visible from (similar to friend classes in C++)
class A {
private@AFriend val something: String = "something"
}
class AFriend {
fun getSomething(a: A): String = a.something
}
And if Kotlin ever gets union types:
internal typealias Alphabet = A | B | C
// use private@AlphabetBen Woodworth
11/19/2021, 5:38 AMfileprivate keyword would be plenty)Klitos Kyriacou
11/22/2021, 9:39 AMfileprivate, should we also have filesealed?jw
11/22/2021, 12:21 PMfileprivate sealed class?Klitos Kyriacou
11/22/2021, 12:25 PMfileprivate sealed class would make the class only accessible to other code in the same file. On the other hand, filesealed would make the class only extendable by other classes in the same file, but the class would be visible outside of that file. That would be the equivalent of Java's sealed classes with the permits clause naming only the classes in the same file.jw
11/22/2021, 3:33 PMpermits approach rather than conflating it with visibility / location.Ben Woodworth
11/22/2021, 6:14 PMsealed class a fileprivate constructor?