Hello, is there a way to enforce a "default visibility" in a library ? I see many libs use the "public" visibility keyword (implying that by default, it is internal). I'm developping a library and that would be great to avoid typing "internal" in front of the majority of my functions.
modifier required—that is, it stops you from making things public by accident—but I don't think it will make things
internal
by default 😞.
n
Nino
01/26/2024, 11:17 AM
That's a start, great !
A part is strange to me tho,
Visibility modifiers are required for declarations if the default visibility exposes them to the public API
. Since the default visiblity is
public
, they will always be exposed to the public API, won't they ?
s
Sam
01/26/2024, 11:23 AM
I think the idea is that something like
Copy code
private class Foo {
val bar = "bar"
}
would still be allowed, since
bar
is not visible from outside even though it has no modifiers. I haven't used that mode myself, though, so maybe someone else can correct me.
n
Nino
01/26/2024, 11:24 AM
I see, thanks! Well, for now I'll start with the explicit API mode, if anyone else have some QoL tools for me, that would be wonderful. Even Java can modify the default visibility of generated code 😞
c
CLOVIS
01/26/2024, 1:34 PM
The default visibility is
public
. If you use explicit API mode, there is no default visibility.
You can write a library without using explicit API mode, if you want to keep
public
as the default.
I don't think you can set another visibility as the default.