File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
docs/docs/reference/changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,25 @@ configure how fields and methods should be resolved.
29
29
30
30
## Example
31
31
32
- <script src =" https://scastie.scala-lang.org/Duhemm/HOZFKyKLTs294XOSYPU5Fw.js " ></script >
32
+ ``` scala
33
+ object StructuralTypeExample {
34
+
35
+ case class Record (elems : (String , Any )* ) extends Selectable {
36
+ def selectDynamic (name : String ): Any = elems.find(_._1 == name).get._2
37
+ }
38
+
39
+ type Person = Record {
40
+ val name : String
41
+ val age : Int
42
+ }
43
+
44
+ def main (args : Array [String ]): Unit = {
45
+ val person = Record (" name" -> " Emma" , " age" -> 42 ).asInstanceOf [Person ]
46
+ println(s " ${person.name} is ${person.age} years old. " )
47
+ // Prints: Emma is 42 years old.
48
+ }
49
+ }
50
+ ```
33
51
34
52
## Extensibility
35
53
You can’t perform that action at this time.
0 commit comments