java 8
functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.
It is adeclarative programming paradigm, which means programming is done with expressions
vs
new Thread(
new Runnable(){
public void run(){
System.out.println("I am another thread!");
}
}
).start();
interface Runnable{
public void run();
}
interface Runnable{
public void run();
}
Interface with exactly one method
interface Predicate<T> {
boolean test(T t);
}
Predicate
void eligibleForDriving(){
matchPerson(
new Predicate<Person>(){
public boolean test(Person p){
return p.getAge() >= 16;
}
}
)
}
void eligibleForDriving(){
matchPerson( new Predicate<Person>(){ public boolean test(Person p){ return p.getAge() >= 16; } }
)
}
{ who -> the hell is who }
void eligibleForDriving(){
matchPerson(p -> p.age > 16);
}
matchTwoPerson((p1,p2)-> p2.age-p1.age);
matchTwoPerson((p1,p2)->{
int result;
result = p2.age - p1.age;
return result;
});
Different Variants ....
void eligibleForDriving(){
matchPersons(p -> p.getAge() >= 16);
}
Lamda expressions are converted to instance of functional interface
Feedbacks please