I am new to Kotlin and I am confused between open
and public
keywords. Could anyone please tell me the difference between those keywords?
相关问题
- How to refresh height of a Constrained View in Con
- Android Room Fetch data with dynamic table name
- Access Binding Adapters in multi module project
- How to make request-bound data globally available
- In Vertx I need to redirect all HTTP requests to t
相关文章
- es 单字段多分词器时,textField.keyword无法高亮
- SonarQube: How to suppress a warning in Kotlin cod
- What are the `^let` annotations in Android Studio
- Create Custom Dagger 2 Scope with Kotlin
- Android Studio 3.5 ERROR: Unable to resolve depend
- Kotlin inlined extension property
- Kotlin Koans with EduTools plugin: “Failed to laun
- “lateinit” or “by lazy” when defining global andro
class A { ... }
in Java is equal toopen class A { ... }
in Kotlin.final class B { ... }
in Java is equal toclass B { ...}
in Kotlin.It is not related with
public
.In Kotlin, everything without access modifiers is
public
by default. You can explicitly saypublic
in the definition, but it is not necessary in Kotlin.So,
and
are the same in Kotlin.
The
open
keyword means “open for extension“:You also need to be explicit about methods you want to make overridable, also marked with
open
:The
public
keyword acts as a visibility modifier that can be applied on classes, functions etc. Note thatpublic
is the default if nothing else is specified explicitly: