Hello,
This is a lab question I'm unsure on.
I have a number of methods each performing a single operation on a number, for example : Switching a sign, applying a sine function or applying a square root.
If I wanted to perform something like the minus of the square root of a sine of a number then how would I replace all these methods with a single method which takes a parameter as a functor. I'm guessing the functor is another method with what we're applying to a number (like the example above)?
I could really do with some help here, thank you in advance :-)
Shuyin
Java generics and functors
Page 1 of 14 Replies - 3219 Views - Last Post: 04 April 2008 - 02:37 AM
Replies To: Java generics and functors
#2
Re: Java generics and functors
Posted 03 April 2008 - 06:09 AM
Shuyin, on 3 Apr, 2008 - 05:50 AM, said:
Hello,
This is a lab question I'm unsure on.
I have a number of methods each performing a single operation on a number, for example : Switching a sign, applying a sine function or applying a square root.
If I wanted to perform something like the minus of the square root of a sine of a number then how would I replace all these methods with a single method which takes a parameter as a functor. I'm guessing the functor is another method with what we're applying to a number (like the example above)?
I could really do with some help here, thank you in advance :-)
Shuyin
This is a lab question I'm unsure on.
I have a number of methods each performing a single operation on a number, for example : Switching a sign, applying a sine function or applying a square root.
If I wanted to perform something like the minus of the square root of a sine of a number then how would I replace all these methods with a single method which takes a parameter as a functor. I'm guessing the functor is another method with what we're applying to a number (like the example above)?
I could really do with some help here, thank you in advance :-)
Shuyin
Easy in C and C++ but not in Java. For security reason you do not want a malicious user or hacker to pass on a custom made function/method to another function expecting one of the standard functions/method.
As there is no arithmetic on pointers in Java there are no pointer to method in Java.
This post has been edited by pbl: 03 April 2008 - 06:12 AM
#3
Re: Java generics and functors
Posted 03 April 2008 - 06:31 AM
#4
Re: Java generics and functors
Posted 04 April 2008 - 01:36 AM
but remember avoid reflection API as its behaviour effects the program at runtime. Not recommended for good commercial apps.
#5
Re: Java generics and functors
Posted 04 April 2008 - 02:37 AM
Hahaha, back to school
But this is Sparta!
Anyway, I am not really sure about the problem, but it seems to me that using some interfaces it could be solved without using method pointers.
Anyway, I am not really sure about the problem, but it seems to me that using some interfaces it could be solved without using method pointers.
Page 1 of 1

New Topic/Question
Reply



MultiQuote




|