Created
December 12, 2013 12:00
-
-
Save diego-aslz/7926987 to your computer and use it in GitHub Desktop.
Proc in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main; | |
| public class DomainClass { | |
| public void doSomething(Object arg0, Proc block) { | |
| // do something | |
| block.run(arg0); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main; | |
| public class Main { | |
| public static void main(String[] args) { | |
| DomainClass mc = new DomainClass(); | |
| mc.doSomething("some argument", new Proc() { | |
| public Object run(Object ... args) { | |
| System.out.println("Proc with: " + args[0]); | |
| return null; | |
| } | |
| }); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main; | |
| public interface Proc { | |
| public Object run(Object ... args); | |
| } |
Author
I believe so, this is probably the closest you can get from Ruby Procs in Java, sadly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this the best way to simulate Procs in Java?