Package protected alternative in Kotlin

后端 未结 3 2080
离开以前
离开以前 2020-12-01 02:31

In Java, we have package protected (default) modifier for classes, which allows us to have many classes in a single package but exposes only a few and keep the logic encapsu

3条回答
  •  Happy的楠姐
    2020-12-01 03:05

    As a workaround for me on android I've created @PackagePrivate annotation and lint checks to control access. Here you can find the project.

    Lint checks are obviously not that strict as compiler checks and some setup needed to fail the build on errors. But android studio picks up lint checks automatically and shows error immediately while typing. Unfortunately I don't know a way to exclude annotated members from autocomplete.

    Also, as lint is a purely compile-time tool, no checks at runtime performed.

提交回复
热议问题