Hello, is there a way to enforce a "default visibi...
# getting-started
n
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.
s
The explicit API mode makes the
public
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
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
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
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
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.