Type conversions

That's what I thought, thanks Andrey.

I was playing with the idea of providing some limited implicit support (only for type conversion). Since it’s so easy to define extension functions in Kotlin, the compiler could look for functions with a certain signature, e.g.

fun to() : T

For example, I could define an implicit conversion from Int to MyClass:

fun Int.to() : MyClass {   return new MyClass(this) }

and then a function taking a MyClass can be passed an Int:

fun f(mc: MyClass) {   ... }

f(3); // will be converted automatically

I think the argument "We can't figure out what's going on" is silly, especially in languages that support extension functions. We have great IDE support already which can tell us everything we need to know without having to browse anything. For example, putting the cursor inside the parenthesis at the call site and pressing Ctrl-p would display all the signatures, both with explicit and implicit parameters.

The reason why I’m suggesting this is that Kotlin is emphasizing its support for DSL but I feel that without this kind of conversion support, DSL’s are severely crippled.

1 Like