11/1/2023 0 Comments Internal keyword in kotlin![]() Internal actual class PlatformSocket actual constructor(url: String) Īnd here is the common logic in the common module that uses the platform-specific class PlatformSocket(). However, in your Gradle build files, you need to use a specific target name from the list of supported targets. Examplesįor simplicity, the following examples use intuitive target names, like iOS and Android. Learn how to add dependencies on platform-specific libraries. Implementing as much functionality as possible in the shared module is better, even if doing so takes more time.ĭon't overuse expected and actual declarations – in some cases, an interface may be a better choice because it is more flexible and easier to test. ![]() Use expected and actual declarations only for Kotlin declarations that have platform-specific dependencies. The IDE provides tools that help you create the missing actual declarations. The compiler ensures that every declaration marked with the expect keyword in the common module has the corresponding declarations marked with the actual keyword in all platform modules. This works for most Kotlin declarations, such as functions, classes, interfaces, enumerations, properties, and annotations. ![]() ![]() With this mechanism, a common source set defines an expected declaration, and platform source sets must provide the actual declaration that corresponds to the expected declaration. If you're developing a multiplatform application that needs to access platform-specific APIs that implement the required functionality (for example, generating a UUID), use the Kotlin mechanism of expected and actual declarations. We'll do our best to minimize any changes you will have to make. It is almost stable, but migration steps may be required in the future. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |