Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anything in Scala equivalent to C#'s `dynamic`?

Tags:

dynamic

scala

I believe the answer is no, but wouldn't hurt to check: anything in Scala that's equivalent to C#'s dynamic keyword? Anything on the horizon?

I know about scala.Dynamic, which is not the same thing - in C# you don't know the types at compile time, and the dynamic type propagates.

I also know about invokedynamic, which is not the same thing - invokedynamic is the infrastructure that would make language constructs like dynamic performant.

Anything on the horizon?

like image 539
Yang Avatar asked Jul 19 '11 04:07

Yang


People also ask

What is Any in Scala?

Any is the supertype of all types, also called the top type. It defines certain universal methods such as equals , hashCode , and toString . Any has two direct subclasses: AnyVal and AnyRef . AnyVal represents value types.

What does _* mean in Scala?

: _* is a special instance of type ascription which tells the compiler to treat a single argument of a sequence type as a variable argument sequence, i.e. varargs.

What is with in Scala?

Use the with Keyword in ScalaThis keyword is usually used when dealing with class compositions with mixins. Mixins are traits that are used to compose a class. This is somewhat similar to a Java class that can implement an interface.

What are the differences between any AnyRef and AnyVal?

Any has two direct subclasses: AnyVal and AnyRef. AnyVal represents value types. There are nine predefined value types and they are non-nullable: Double, Float, Long, Int, Short, Byte, Char, Unit, and Boolean. AnyRef represents reference types.


1 Answers

Yes there is: objects extending the Dynamic trait behave similarly to variables declared as dynamic in C#.

This is a new feature in Scala 2.9 (but still considered experimental), see the scaladoc at http://www.scala-lang.org/api/current/index.html#scala.Dynamic.

like image 151
Christophe Vanfleteren Avatar answered Sep 23 '22 00:09

Christophe Vanfleteren