Skip to main content
InterviewHubPRO
Section Overview
Q37

Question 37 of 50

Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)

74%
Kotlin & Coroutines (50 Qs)•Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)

Kotlin Multiplatform (KMP): `expect`/`actual` declarations and shared architecture across iOS and Android.

senior LevelCode ExampleFormsPerformanceSystem Design

In Simple Words: KMP allows compiling pure Kotlin business logic (networking, local databases, ViewModels, analytics) to native code across iOS and Android:

  • Shared Code (commonMain): Standard Kotlin code shared across all targets.
  • Platform Bridging (expect / actual):
    kotlin
    // commonMain
    expect fun getPlatformName(): String
    
    // androidMain
    actual fun getPlatformName(): String = "Android ${Build.VERSION.SDK_INT}"
    
    // iosMain
    actual fun getPlatformName(): String = UIDevice.currentDevice.systemName()
    
  • Compiles into native .aar for Android and native Apple .xcframework for iOS with zero runtime bridge overhead.