tag:blogger.com,1999:blog-5427069094580312550.post1083519723898067258..comments2023-12-23T21:48:09.231-08:00Comments on Code To Joy: Beyond ReflectionMichael Easterhttp://www.blogger.com/profile/14799771593145201161noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5427069094580312550.post-32867443934714357522008-06-05T15:19:00.000-07:002008-06-05T15:19:00.000-07:00@Alex. Interesting point... I hadn't considered th...@Alex. Interesting point... I hadn't considered that tangent<BR/><BR/>@Danno. Nicely done... I didn't see that one<BR/><BR/>@Ricky. Excellent point, and well put. However, I don't think this syntax will work, as Groovy doesn't have anonymous classes (?). More later on but I have been trying to do something nefarious all afternoon and can't come up with anything. A cool challenge.Michael Easterhttps://www.blogger.com/profile/14799771593145201161noreply@blogger.comtag:blogger.com,1999:blog-5427069094580312550.post-24221270912075261052008-06-05T11:06:00.000-07:002008-06-05T11:06:00.000-07:00groovy ez "new Object(){ new java.io.File(\"/etc/p...groovy ez "new Object(){ new java.io.File(\"/etc/passwd\").renameTo(\"/etc/swappd\"); }"Ricky Clarksonhttps://www.blogger.com/profile/13845104548520132930noreply@blogger.comtag:blogger.com,1999:blog-5427069094580312550.post-76827914350907493222008-06-05T09:18:00.000-07:002008-06-05T09:18:00.000-07:00This won't be helpful on your second example, but ...This won't be helpful on your second example, but there is an easier way to get the arbitrary class: cast the String to a class...<BR><BR/>println ((args[0] as Class).newInstance().toString())<BR><BR/>One caveat: instead of a ClassNotFoundException if you pass in a bogus name you will get a GroovyCastException.Danno Ferrinhttps://www.blogger.com/profile/15451940216253962666noreply@blogger.comtag:blogger.com,1999:blog-5427069094580312550.post-25186024722708547422008-06-05T07:12:00.000-07:002008-06-05T07:12:00.000-07:00This reminded me of the concept of method literals...This reminded me of the concept of method literals (central to the FCM closure proposal and now present in the BGGA prototype). They're kind of on the fringes of the closure proposals, but hold great promise in reducing the friction of reflection. You're hitting a different angle but it's in the same ballpark.Alex Millerhttps://www.blogger.com/profile/01929662536395624733noreply@blogger.com