Bird
0
0

Find the issue in this Kotlin code:

medium📝 Debug Q7 of 15
Kotlin - Data Types
Find the issue in this Kotlin code:
fun printValue(value: Any) {
    println(value.length)
}

printValue("test")
AAny type does not have a length property
BFunction printValue must return a value
CString cannot be passed to Any parameter
DMissing import for length property
Step-by-Step Solution
Solution:
  1. Step 1: Check property access on Any

    Any type does not have a length property.
  2. Step 2: Understand type casting necessity

    To access length, value must be cast to String or checked with is String.
  3. Final Answer:

    Any type does not have a length property. -> Option A
  4. Quick Check:

    Accessing properties requires correct type [OK]
Quick Trick: Cast Any to specific type before accessing properties [OK]
Common Mistakes:
MISTAKES
  • Assuming Any has all properties
  • Ignoring need for type check or cast
  • Thinking function must return value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes