tag:blogger.com,1999:blog-741750605858169835.post4935256794742543928..comments2024-01-24T14:53:02.919+00:00Comments on Stephen Colebourne's blog: Java language - method adaptionStephen Colebournehttp://www.blogger.com/profile/01454237967846880639noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-741750605858169835.post-6658422083078909832007-02-06T19:24:36.000+00:002007-02-06T19:24:36.000+00:00Or in other words, I think BGGA is easier to read,...Or in other words, I think BGGA is easier to read, more useful, and is more likely to lead to good code.Tom Palmerhttp://bagotricks.com/blog/noreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-40689183088189053522007-02-06T19:22:23.000+00:002007-02-06T19:22:23.000+00:00I think anonymous code blocks (a la BGGA) are easi...I think anonymous code blocks (a la BGGA) are easier to read and better fit good code style rather than trying to make arbitrary methods on my class that happen to look like methods in another class. And if I need to map multiple methods, I think current mechanisms in Java are good enough. <br /><br />I still think method references might be helpful to avoid reflection in some cases, though, and it would be nice if property reference syntax also worked for methods. But again, that's mostly just a reflection avoidance issue. Probably not a common programming case. Well for properties yes, but not for methods.Tom Palmerhttp://bagotricks.com/blog/noreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-81792250272473760832007-02-06T15:22:21.000+00:002007-02-06T15:22:21.000+00:00@Quintesse, I know this only addresses some of the...@Quintesse, I know this only addresses some of the closure use cases. Thats why I used the word 'some' in the blog :-)<br /><br />Your code fragment is not what I intend, this is what I'm thinking of:<br /><br />MyRunnable r = (MyRunnable->run(int,int))this->processTask(int,int); <br /><br />Your foo and bar have no place here. The two int parameters are just passed through within the generated inner class.<br /><br />It would not be possible to pass parameters to the constructor of the inner class.<br /><br />@Carlos, Labels is an interesting idea. Not sure if it overcomplicates though. Why not just add two listeners:<br /><br />window.addKeyListener((KeyListener->keyPressed) this->keyDown(KeyEvent));<br />window.addKeyListener((KeyListener->keyReleased) this->keyUp(KeyEvent));Stephen Colebournenoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-4822708637373775182007-02-06T10:12:44.000+00:002007-02-06T10:12:44.000+00:00What about using labels for the cases where the ad...What about using labels for the cases where the adapted interface has more then one method?<br />For example:<br /><br />window.addKeyListener(<br /> keyPressed: this->keyDown(KeyEvent),<br /> keyReleased: this->keyUp(KeyEvent)<br />);<br /><br />This wound be translated to:<br /><br />window.addKeyListener(new KeyListener(){<br /> public void keyPressed(KeyEvent e) { keyDown(e) }<br /> public void keyReleased(KeyEvent e) { keyUp(e) }<br /> public void keyTyped(KeyEvent e) { }<br />});<br /><br />Each label indicates which method has to be called. Any method not labeled is implemented as "do nothing". Alternatively, the programmer should be obligated to label all methods, with some special syntax to indicate the "do noting" intend.Carlos Gesserhttp://gesser@gmail.comnoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-54141496027812188182007-02-06T10:00:39.000+00:002007-02-06T10:00:39.000+00:00"I object to using closures when there are tw..."I object to using closures when there are two sets of rules for what you can and can't write in the body of the closure. Method adaption is one possible solution to some closure use cases."<br /><br />But your proposal only addresses a tiny part of all the possible use-cases that closures would open up. So this would either mean forgetting about all the other things that closures would bring to the table (a wasted opportunity IMO) or find alternatives for all/most of them (which seems silly).<br /><br />"@Jesse, Your example would not be legal - the adaption must be to a method with the same signature."<br /><br />But what if I have my own Runnable that does have a method like that? Something like this for example:<br /><br />MyRunnable r = (MyRunnable->run(int,int))this->processTask(foo,bar);<br /><br />If that's possible in which context would foo and bar be resolved? And how would it be possible to pass arguments to the constructor of MyRunnable?<br /><br />Or is your proposal only meant to be used with Runnable?quintessenoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-71695366930206908452007-02-06T08:56:29.000+00:002007-02-06T08:56:29.000+00:00@Jesse, Your example would not be legal - the adap...@Jesse, Your example would not be legal - the adaption must be to a method with the same signature.<br /><br />@m, I offered two options - one with the cast and one without. For executor, its obvious what to do, so perhaps the without a cast version is an optimised form of the with a cast version.<br /><br />For method literals, I'm choosing to make 'this' mandatory, so your example won't come about.<br /><br />As I said, this is an alternative to closures. If you've read my other posts, I object to using closures when there are two sets of rules for what you can and can't write in the body of the closure. Method adaption is one possible solution to some closure use cases.Stephen Colebournenoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-63210108245789573982007-02-06T02:05:47.000+00:002007-02-06T02:05:47.000+00:00How would the object instance and paramters intera...How would the object instance and paramters interact with this? For example, would this be legal:<br /> Runnable->run r = foo->someMethod(bar, baz);Jesse Wilsonhttp://publicobject.com/noreply@blogger.com