
-----------------------------------
Raknarg
Mon Nov 04, 2013 1:07 pm

Passing a method as a parameter
-----------------------------------
I was wondering if it was possible to set a parameter or variable as a method. In turing, for instance, you can do this:


var thing : proc x

proc hi
   put "hi"
end hi

thing := hi


Or in Python there's a method called reduce whose first argument takes in a function. Is there anything like that in java?

-----------------------------------
Raknarg
Mon Nov 04, 2013 1:58 pm

RE:Passing a method as a parameter
-----------------------------------
Oh I just discovered you can use "implement" to do sort of the same thing, you define a bunch of classes with one method that is the function you want.

Any other ideas out there?

-----------------------------------
rdrake
Mon Nov 04, 2013 2:57 pm

Re: Passing a method as a parameter
-----------------------------------
Right now you can use an [url=http://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html]anonymous inner class.  Once Java joins the future, you can also use [url=http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html]lambda functions like in Python.

-----------------------------------
Raknarg
Mon Nov 04, 2013 3:51 pm

RE:Passing a method as a parameter
-----------------------------------
Well technically speaking I'm not using Java, but something based off of Java (Processing, in case you're curious), so what I stated above works in it but I don't think I can do that
