Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

pass function with parameters

# std::bind in python, or passing functions with paramaters can be done in two ways:
# with 'functools' or with lambda functions

# 1. functools: --------------------------
>>> from functools import partial

>>> def foobar(a, b):
...     return a+b

>>> p = partial(foobar, 1, 2)
>>> p()
3

>>> p2 = partial(foobar, 1)
>>> p2(2)
3

# 2. lambda: --------------------------

>>> def foobar(a,b):
...     return a+b
>>> foobar(1,2) # call normal function
3

>>> bind = lambda x: foobar(x, 2) # bind 2 to foobar
>>> bind(1) 
3

>>> bind = lambda: foobar(1,2) # bind all elements  
>>> bind()  
3
Comment

pass a function as parameter

public interface MyInterface {
    String doSomething(int param1, String param2);
}
class MyClass {
    public MyInterface myInterface = (p1, p2) -> { return p2 + p1; };
}

new Thread(this::someMethod).start();
Comment

PREVIOUS NEXT
Code Example
Java :: abstract method declaration 
Java :: initilize an array java 
Java :: Java List Add Elements using add() method 
Java :: java for item in array 
Java :: Java How to use List? 
Java :: flutter unable to find bundled java version 
Java :: Design a class ‘Complex ‘with data members for real and imaginary part. Provide default and Parameterized constructors. Write a program to perform arithmetic operations of two complex numbers. 
Java :: java static variable 
Java :: Error:java: error reading C:UsersMeriem.m2 epositoryorgapachecommonscommons-lang33.12.0commons-lang3-3.12.0.jar; error in opening zip file 
Java :: add recyclerview in fragment 
Java :: jaccard index two vectors R 
Java :: android check free space programmatically 
Java :: how to convert a string of characters to a stream of binary characters binary 
Java :: how to convert infix to postfix and prefix in java 
Java :: org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:876) 
Java :: quebra de linha java 
Java :: string to char 
Java :: display two dimensional array java 
Java :: how to call a non static method 
Java :: arraylist<hashmap<string, string arraylist = new arraylist<() 
Java :: netbeans android sdk location 
Java :: java set file folder permissions 
Java :: contient java 
Java :: show all spring boot beans 
Java :: Java Creating a TreeMap 
Java :: instance of 
Java :: create thread java 
Java :: initialize empty dictionary java 
Java :: multiple spinner android 
Java :: finding the ascii value of a character in java 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =