Dynamic Type


#1

According to the roadmap on this post, the next iteration(s) of Kotlin will support dynamic type. What are the current thoughts on how this will work? Will it behave similary to C# dynamic keyword?


Access to JavaScript environment
#2

The plan is as follows:

  • Introduce the dynamic keyword, so that
    • dynamic<Foo> is a dynamic variable whose type is at least Foo: all the calls to Foo's members are static, everything else is dynamic
    • dynamic with no type arguments means "dynamic<Any?>"
  • A dynamic call is translated to something like DynamicStrategy.invoke(receiver, "methodName", args)
    • Concrete dynamic strategies may be contributed by users, teh defaul one will be something like what Groovy does.

#3

Awesome, so I assume the following code will work in the future

``

package Kotlin101.Objects.Expressions

fun main (args : Array<String>){
  val msg = anythingGoes()
  println ("${msg?.message}")
}

fun anythingGoes() : dynamic{
  return object{
  val message : String = “You can use this anytime”
  }
}


#4

Yes