Results 1 to 9 of 9
Thread: Function pointers?
- 01-17-2011, 04:18 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 22
- Rep Power
- 0
Function pointers?
Hiya, I'm working on something where be able to pass functions around would be extremely useful. But I don't see anywhere if Java can do it? Can it?
Thanks for any help.
~Aedon
Addendum: I am aware of using interfaces, but I was curious if there was a more direct way to accomplish this.Last edited by AedonetLIRA; 01-17-2011 at 04:21 AM. Reason: Addendum 1
- 01-17-2011, 04:42 AM #2
Nope! Java doesn't have closures like that - Ruby does though! :D
-
I think that Java 7 was supposed to have them (Lambda expressions), but I've heard that it's now been delayed until Java 8.
- 01-17-2011, 04:57 AM #4
Member
- Join Date
- Oct 2010
- Posts
- 22
- Rep Power
- 0
- 01-17-2011, 04:58 AM #5
I'm not sure I like the idea of including it - passing code blocks would be handy in some cases, but its dangerous and encourages lazy design IMHO. Java is one of those languages who's beauty has often been the product of its limitations - making it easy to pick up, and forceful in making you really design your system OOP style. Maybe not as much as ObjC, but its much simpler than ObjC too :D
- 01-17-2011, 05:28 AM #6
Member
- Join Date
- Oct 2010
- Posts
- 22
- Rep Power
- 0
True, but there are times where the usefulness. For instance cycling through a list of actions that an object has and passing it to someone.
- 01-17-2011, 05:33 AM #7
Maybe you can think of a specific example where this wouldn't work, but I think this is usually accomplished using interfaces and passing objects to each other - allowing each object to implement its own actions, but all functioning under a global method call.
- 01-17-2011, 05:43 AM #8
Member
- Join Date
- Oct 2010
- Posts
- 22
- Rep Power
- 0
And they do, I'm more thinking of something like uh:
class obj extends BigObj// method list
doSomething1()
doSomething2()
...
doSomethingN()
And being able to just have an object pass an array of all the doSomethings to whoever need them. I could hard code it, but if an iteration of BigObj has a differing amount of doSomething()'s that need to be used, It would end up being a massive pain.
- 01-18-2011, 04:01 AM #9
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Yup, an interface could do it. You could pass an array of the interface to the object, and they could call the method on the interface objects.
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
Similar Threads
-
pointers needed please (re: MouseListener)
By SM2010 in forum New To JavaReplies: 2Last Post: 05-26-2010, 12:17 PM -
Does Java support pointers?
By kthaker in forum New To JavaReplies: 2Last Post: 10-07-2009, 08:16 AM -
pointers and wrapper classes
By becky in forum New To JavaReplies: 11Last Post: 02-07-2009, 03:59 AM -
Java pointers? How to...
By Krooger in forum New To JavaReplies: 4Last Post: 11-04-2008, 08:30 PM -
Pointers
By ravian in forum New To JavaReplies: 5Last Post: 11-28-2007, 01:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks