Created
July 31, 2019 15:16
-
-
Save varmas/d3df4cf26f030e595c451a6dd57540dc to your computer and use it in GitHub Desktop.
dynamic class instantiation in scala [using structural typing]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package a.b.c | |
class ABC { | |
def foo(bar: String): String = s"wololo.... $bar" | |
} | |
object ABCRunner { | |
type Sample = { def foo(bar: String): String } | |
def main(args: Array[String]) { | |
val baz = Class.forName("a.b.c.ABC").newInstance.asInstanceOf[Sample] | |
println(baz.foo("boo")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment