Skip to content

Instantly share code, notes, and snippets.

@varmas
Last active July 31, 2019 15:18
Show Gist options
  • Save varmas/37c9fa500794af389f5fa62be5834284 to your computer and use it in GitHub Desktop.
Save varmas/37c9fa500794af389f5fa62be5834284 to your computer and use it in GitHub Desktop.
dynamic class instantiation in scala [using inheritance]
class ABC {
def foo(bar: String): String = s"wololo.... $bar"
}
class CDA extends ABC
object ABCRunner {
def main(args: Array[String]) {
val baz = Class.forName("a.b.c.CDA").newInstance.asInstanceOf[ABC]
println(baz.foo("boo"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment