How to pass a method as a parameter using lambdas is discussed here:
Java Pass Method as Parameter
In other languages, namely C++, it is possible to bind a function to it's parameters using Lambdas - discussed here:
Bind Vs Lambda?
Is it possible, in Java, to bind a method using lambdas?
If so, how would you accomplish this?
Edit >>>>
An example, by request, of what I am generally trying to do:
Be warned, there is pseudo code here.
public class DataView {
private static ArrayList<Float> rectData = new ArrayList<Float>();
private static ArrayList<Float> textData = new ArrayList<Float>();
DataView(){
//Pseudo Code:
boundFunction mybind = boundFunction(functionA, 5, 10);
boundFunction mybind2 = boundFunction(functionB, 10, 12);
iter(mybind);
iter(mybind2);
}
//Method with pseudo parameter
private void iter(functionSignature){
for(Float i : textData){
//Pseudo call to pseudo parameter
functionSignature();
}
}
private void functionA(int a, int b){
//dostuff
}
private void functionB(int a, int b){
//do other stuff
}
}
Bare in mind, I'm not looking for 'another way to accomplish this functionality' - this example is to illustrate a general way in which I would like to use functions as parameters, and to bind parameters to those functions.
Edit>>>
Attempt using anonymous classes:
public class DataView {
private class Bound{
public void run(){}
}
private static ArrayList<Float> rectData = new ArrayList<Float>();
private static ArrayList<Float> textData = new ArrayList<Float>();
DataView(){
Bound mybind = new Bound(){
public void run(){
functionA(5,10);
}
};
Bound mybind2 = new Bound(){
public void run(){
functionB(5,10);
}
};
iter(mybind);
iter(mybind2);
}
private void iter(Bound function){
for(Float i : textData){
function.run();
}
}
private void functionA(int a, int b){
//dostuff
}
private void functionB(int a, int b){
//do other stuff
}
}