final
class
Constructor[F] extends AnyVal
Instance Constructors
-
new
Constructor(newInstance: F)
Value Members
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
def
+(other: String): String
-
def
->[B](y: B): (Constructor[F], B)
-
final
def
==(arg0: Any): Boolean
-
final
def
asInstanceOf[T0]: T0
-
-
-
-
-
def
formatted(fmtstr: String): String
-
def
getClass(): Class[_ <: AnyVal]
-
final
def
isInstanceOf[T0]: Boolean
-
val
newInstance: F
-
def
toString(): String
-
def
→[B](y: B): (Constructor[F], B)
An implicit value for dynamically creating classes and traits, especially dynamic mixins.
Usage
Motivation
This feature is useful for library authors. A library author may ask his user to create a
trait
type, then dynamically mix-in it with the features provided by the library.Suppose you are creating a DSL that compiles to JavaScript.
You want your DSL is extensible. For example, the DSL users should be able to create custom binary operators.
With the help of
Constructor.scala
, you can put the boilerplate code into a private classBinaryOperator
:The users only need a very simple implementation for their custom binary operators.
An alternative approach
There is another approach to integrate partial implementation from users: asking users to provide custom callback functions or type classes.
However, the callback functions or type classes approach will create additional object instances and additional references for each instance at run-time. On the other hand, the
Constructor.scala
approach create classes at compile-time and no additional run-time references. As a result, at run-time,Constructor.scala
approach will consume less memory, and performs less indirect access on memory.Author:
杨博 (Yang Bo) <[email protected]>