Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Passing a method as a parameter
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Raknarg




PostPosted: Mon Nov 04, 2013 1:07 pm   Post subject: 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:

Turing:

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?
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Mon Nov 04, 2013 1:58 pm   Post subject: 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




PostPosted: Mon Nov 04, 2013 2:57 pm   Post subject: Re: Passing a method as a parameter

Right now you can use an anonymous inner class. Once Java joins the future, you can also use lambda functions like in Python.
Raknarg




PostPosted: Mon Nov 04, 2013 3:51 pm   Post subject: 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
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: