Retrieving original class types from anonymous classes <p>Given a class with an empty constructor and a var:</p> <pre><code>class MyClass() { var myVar: Int = 0 } </code></pre> <p>When the class is instantiated with a closure, this yields an object with the underlying type of an anonymous class rather than MyClass:</p> <pre><code>// getClass yields type my.package.MainClass$$anonfun$1$anonfun$apply... val myNewClassInstance: MyClass = new MyClass() { myVar = 2} </code></pre> <p>Is it possible to retrieve the original class type MyClass using reflection and the object myNewClassInstance, in order to create new object instances from it?</p>