Linked Questions

552 votes
8 answers
967k views

How to pass a function as a parameter in Java? [duplicate]

In Java, how can one pass a function as an argument to another function?
Jason's user avatar
  • 5,701
19 votes
8 answers
64k views

How do I pass method as a parameter in Java? [duplicate]

Possible Duplicate: Java Pass Method as Parameter Is it possible to pass a method as a parameter in Java? If I can't what would be the best course of action for the method below without having to ...
Indy411's user avatar
  • 3,776
1 vote
4 answers
16k views

How to pass a member function as a parameter in java? [duplicate]

My collect() function calls Foo.f(). I would like to make Foo.f() itself a parameter of my function. Is this possible in Java? How can I pass either Foo.f() or Foo.g() (or any other function of Foo ...
Micha Wiedenmann's user avatar
5 votes
3 answers
24k views

How to pass methods as parameters? [duplicate]

I have a class with bunch of methods. In another class, I need to write a method, that handles the input values. To that method, I want to pass the method of the class that I want to call. How can we ...
newwebdev's user avatar
  • 427
3 votes
5 answers
2k views

Java: Passing a Function as a Parameter like in JavaScript? [duplicate]

I'm trying to write a function, so I can pass a function as a parameter, such as public class HashFunction { private Function f; public HashFunction(Function f) { this.f=f; } ...
user1277170's user avatar
  • 3,237
3 votes
2 answers
1k views

Java 8 how to pass a non-functional method as parameter [duplicate]

I have a class which contains multiple methods: Class SimpleClass { methodA(var1, var2) { //body } methodB(var1, var2) { //body } .... } Using java 8 Lambda, can I ...
suraj bahl's user avatar
  • 3,356
0 votes
1 answer
6k views

Passing getter/setter as a method reference [duplicate]

I have a bunch of entries like these two: if (update) { if (activity.getName() == null) { logger.debug(" Setting name on " + id); } else ...
dijxtra's user avatar
  • 2,761
3 votes
1 answer
3k views

What is the Java equivalent of a JavaScript callback? [duplicate]

I am experienced in JavaScript but new to Java. I am trying to figure out how to pass a function as a parameter of another function. In JavaScript this would like the block in Figure 1. Figure 1 ...
T. Junghans's user avatar
  • 11.7k
1 vote
2 answers
3k views

Is there a way to pass a method as a parameter to a method? [duplicate]

I'm writing a program and I want to know if I can pass a method as a parameter of another method. For example, something of the following: public boolean update(Method m){ //input is a method int ...
user3642365's user avatar
0 votes
3 answers
1k views

How to call a method with function input in Java? [duplicate]

I have a Class that have a function like this: public class Entity{ public void apply(final Function<Item, Item> function) {} } How do make a Call in such method? Example: Entity entity ...
Sham Fiorin's user avatar
4 votes
4 answers
131 views

I need to understand syntax of this java code [duplicate]

Can some please help me with syntax of following java code? list.stream() .filter(name -> name.startsWith("f")) .map(String::toUpperCase) .sorted() .forEach(System.out::println);` is ...
MTARIQ's user avatar
  • 75
0 votes
1 answer
968 views

Actual parameters in Java [duplicate]

I'm new to Java and I'm confused about actual parameters in Java. Since it's just parameters, I assume that literals, constants,variables, expressions can be actual parameters during function calling. ...
clink's user avatar
  • 213
-2 votes
2 answers
315 views

Java - Passing and executing a function [duplicate]

Is there a way of passing a function to another function and then executing it? functionCaller(functionToBeCalled());
Device's user avatar
  • 567
0 votes
4 answers
303 views

Java: Specify method in method parameters? [duplicate]

Is it possible to specify a method as a method parameter? e.g. public void someMethod(String blah, int number, method MethodName) Where MethodName is the name of a different method that needs to be ...
Blackvein's user avatar
  • 558
1 vote
1 answer
100 views

Is it possible to have a non static method as a parameter [duplicate]

public static String answer(vector alpha, vector beta){ return (alpha.additionVector(beta)).vectortoString(); } I want to apply this method to other operations. However, the other operators ...
MA w's user avatar
  • 13

15 30 50 per page
1
2 3 4 5