{"action":"created","issue":{"url":"https://api.github.com/repos/alexarchambault/jupyter-scala/issues/43","labels_url":"https://api.github.com/repos/alexarchambault/jupyter-scala/issues/43/labels{/name}","comments_url":"https://api.github.com/repos/alexarchambault/jupyter-scala/issues/43/comments","events_url":"https://api.github.com/repos/alexarchambault/jupyter-scala/issues/43/events","html_url":"https://github.com/alexarchambault/jupyter-scala/issues/43","id":126957216,"number":43,"title":"Creating REPL Classes using Reflection","user":{"login":"kmader","id":116120,"avatar_url":"https://avatars.githubusercontent.com/u/116120?v=3","gravatar_id":"","url":"https://api.github.com/users/kmader","html_url":"https://github.com/kmader","followers_url":"https://api.github.com/users/kmader/followers","following_url":"https://api.github.com/users/kmader/following{/other_user}","gists_url":"https://api.github.com/users/kmader/gists{/gist_id}","starred_url":"https://api.github.com/users/kmader/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmader/subscriptions","organizations_url":"https://api.github.com/users/kmader/orgs","repos_url":"https://api.github.com/users/kmader/repos","events_url":"https://api.github.com/users/kmader/events{/privacy}","received_events_url":"https://api.github.com/users/kmader/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-15T21:00:28Z","updated_at":"2016-01-15T23:19:18Z","closed_at":null,"body":"Classes that are created in the REPL cannot be initiated using reflection (they show up with one argument when they should have 0).\r\n\r\nA simple example is shown here\r\nA normal class can be created without any problem\r\n```scala\r\nval testBasic = Try{classOf[java.io.ByteArrayOutputStream].newInstance()}\r\ntestBasic: scala.util.Try[java.io.ByteArrayOutputStream] = Success()\r\n```\r\n\r\nMaking the classes in the REPL (even with a few tricks) \r\n```scala\r\nclass TestClassA\r\nobject TestObjA {\r\n    class TestClassB\r\n}\r\nobject TestObjB {\r\n    class TestClassC\r\n}\r\n```\r\n\r\nWorks fine with standard methods\r\n```scala\r\nval testA1 = new TestClassA\r\nval testB1 = new TestObjA.TestClassB\r\nimport TestObjB._\r\nval testC1 = new TestClassC\r\ntestA1: cmd2.INSTANCE.$ref$cmd0.TestClassA = cmd0$$user$TestClassA@65100245\r\ntestB1: cmd2.INSTANCE.$ref$cmd0.TestObjA.TestClassB = cmd0$$user$TestObjA$TestClassB@18654dc1\r\nimport TestObjB._\r\ntestC1: cmd2.INSTANCE.$ref$cmd0.TestObjB.TestClassC = cmd0$$user$TestObjB$TestClassC@54bd18ab\r\n```\r\n\r\nbut not with reflection\r\n```scala\r\nimport scala.util.Try\r\nval testA2 = Try{classOf[TestClassA].newInstance()}\r\nval testB2 = Try{classOf[TestObjA.TestClassB].newInstance()}\r\nval testC2 = Try{classOf[TestClassC].newInstance()}\r\n```\r\n\r\n```\r\ntestA2: scala.util.Try[cmd4.INSTANCE.$ref$cmd0.TestClassA] = Failure(java.lang.InstantiationException: cmd0$$user$TestClassA)\r\ntestB2: scala.util.Try[cmd4.INSTANCE.$ref$cmd0.TestObjA.TestClassB] = Failure(java.lang.InstantiationException: cmd0$$user$TestObjA$TestClassB)\r\ntestC1: scala.util.Try[cmd4.INSTANCE.$ref$cmd0.TestObjB.TestClassC] = Failure(java.lang.InstantiationException: cmd0$$user$TestObjB$TestClassC)\r\n```\r\n\r\nSee a more detailed example [here](https://github.com/4Quant/ImgLib2-Notebooks/blob/master/Create%20Ops.ipynb). A similar problem is listed [here](http://fiji.sc/bugzilla/show_bug.cgi?id=874)"},"comment":{"url":"https://api.github.com/repos/alexarchambault/jupyter-scala/issues/comments/172124100","html_url":"https://github.com/alexarchambault/jupyter-scala/issues/43#issuecomment-172124100","issue_url":"https://api.github.com/repos/alexarchambault/jupyter-scala/issues/43","id":172124100,"user":{"login":"alexarchambault","id":7063723,"avatar_url":"https://avatars.githubusercontent.com/u/7063723?v=3","gravatar_id":"","url":"https://api.github.com/users/alexarchambault","html_url":"https://github.com/alexarchambault","followers_url":"https://api.github.com/users/alexarchambault/followers","following_url":"https://api.github.com/users/alexarchambault/following{/other_user}","gists_url":"https://api.github.com/users/alexarchambault/gists{/gist_id}","starred_url":"https://api.github.com/users/alexarchambault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexarchambault/subscriptions","organizations_url":"https://api.github.com/users/alexarchambault/orgs","repos_url":"https://api.github.com/users/alexarchambault/repos","events_url":"https://api.github.com/users/alexarchambault/events{/privacy}","received_events_url":"https://api.github.com/users/alexarchambault/received_events","type":"User","site_admin":false},"created_at":"2016-01-15T23:19:18Z","updated_at":"2016-01-15T23:19:18Z","body":"Adding `import special.wrap.obj` in the cell defining the classes makes your example work, see https://gist.github.com/alexarchambault/d115ae3585d262f01700. This has the effect of modifying the way the kernel compiles the code of the cell, which in turn makes it easier to use the classes it defines reflectively or with macros.\r\n\r\nThis ought to be written in a doc somewhere, sorry it's not yet... I guess I'll write one for the next major version of jupyter-scala, which should be soon."}}