https://kotlinlang.org logo
#announcements
Title
# announcements
o

Olekss

10/08/2019, 2:08 PM
today got interesting confusion Method accepting parameter as Any type, and by kotlin syntax definition client invoked this method not with round brackets but with curly brackets, and as type is Any, the syntax and compiler accepted it and method was invoked with closure type, which broke the runtime Is it possible somehow to restrict or avoid such behaviour on compile time level?
s

spand

10/08/2019, 2:12 PM
What was the error ?
s

Shawn

10/08/2019, 2:14 PM
yeah what do you mean by “broke the runtime”
I just tried this in a scratch file, no errors
w

wasyl

10/08/2019, 2:15 PM
I assume the error was that function that accepted
Any
was working with an assumption that that the parameter would be of non-functional type?
c

Chris Miller

10/08/2019, 2:29 PM
Sounds like something the code should just deal with - it is accepting "Any" after all. Maybe an inspection could be created that warns the developer, but I'm not sure the compiler should be getting involved here
o

Olekss

10/08/2019, 6:50 PM
yea, found the solution
add the second parameter with default value, then it's not possible to send closure by accident
s

Shawn

10/08/2019, 6:52 PM
that sounds like a pretty roundabout solution
that doesn’t exactly address the core issue
😂 1
1
2 Views