Which of these calls will cause a compilation error?
hard
A. sumList(listOf("1", "2", "3"))
B. sumList(listOf(1.5, 2.5, 3.5))
C. sumList(listOf(1, 2, 3))
D. sumList(listOf(1L, 2L, 3L))
Solution
Step 1: Analyze the function's type constraint
The function requires a List of elements where each element is a subtype of Number.
Step 2: Check each call's argument type
Options B, C, and D pass lists of Double, Int, and Long respectively. sumList(listOf("1", "2", "3")) passes a list of Strings, which are not subtypes of Number, causing a compilation error.
Final Answer:
sumList(listOf("1", "2", "3")) -> Option A
Quick Check:
Only Number subtypes allowed, String list fails [OK]
Hint: Only Number subtypes allowed in sumList argument [OK]
Common Mistakes:
Passing String list instead of Number list
Assuming any list works
Ignoring generic type constraints
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.