Bird
0
0

Why does Kotlin allow platform types to be assigned to both nullable and non-nullable variables without compiler errors?

hard📝 Conceptual Q10 of 15
Kotlin - Null Safety
Why does Kotlin allow platform types to be assigned to both nullable and non-nullable variables without compiler errors?
ABecause Kotlin treats all Java types as nullable by default
BBecause Kotlin trusts Java code and skips null checks
CBecause platform types represent unknown nullability from Java
DBecause Kotlin disables null safety for Java interop
Step-by-Step Solution
Solution:
  1. Step 1: Understand platform type concept

    Platform types represent Java types with unknown nullability.
  2. Step 2: Kotlin's flexible assignment rules

    Kotlin allows assigning platform types to nullable or non-nullable variables because it cannot be sure if null is possible.
  3. Final Answer:

    Because platform types represent unknown nullability from Java -> Option C
  4. Quick Check:

    Platform types = unknown nullability from Java [OK]
Quick Trick: Platform types mean Kotlin can't infer Java nullability [OK]
Common Mistakes:
MISTAKES
  • Thinking Kotlin disables null safety
  • Assuming all Java types are nullable
  • Believing Kotlin trusts Java blindly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes