Scala Language Dynamic Invocation

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Scala allows you to use dynamic invocation when calling methods or accessing fields on an object. Instead of having this built deep into the language, this is accomplished through rewriting rules similar to those of implicit conversions, enabled by the marker trait [scala.Dynamic][Dynamic scaladoc]. This allows you to emulate the ability to dynamically add properties to objects present in dynamic languages, and more. [Dynamic scaladoc]: http://www.scala-lang.org/api/2.12.x/scala/Dynamic.html

Syntax

  • class Foo extends Dynamic
  • foo.field
  • foo.field = value
  • foo.method(args)
  • foo.method(namedArg = x, y)

Remarks

In order to declare subtypes of Dynamic, the language feature dynamics must be enabled, either by importing scala.language.dynamics or by the -language:dynamics compiler option. Users of this Dynamic who do not define their own subtypes do not need to enable this.



Got any Scala Language Question?