Skip to content

Instantly share code, notes, and snippets.

@saichaitanyan
Created January 30, 2019 05:03
Show Gist options
  • Save saichaitanyan/8fa88e9703f3b84154e54e6d62ae5975 to your computer and use it in GitHub Desktop.
Save saichaitanyan/8fa88e9703f3b84154e54e6d62ae5975 to your computer and use it in GitHub Desktop.
Lambda Expressions
package lambda;
/*
* Lambda expressions basically express instances of functional interfaces.
* An interface with single abstract method is called functional interface.
* An example is java.lang.Runnable.
* lambda expressions implement the only abstract function and therefore implement functional interfaces
* */
public class Test {
public static void main(String[] args) {
FuntionalInterf interf = (int z) -> System.out.println(">>>>>>> " + (2 * z));
// interf.setFun(7);
// interf.getFun();
WithoutLambda.main();
}
}
class WithoutLambda {
public static void main() {
FuntionalInterf f = new FuntionalInterf() {
@Override
public void setFun(int x) {
System.out.println(":::::: " + (2 * x));
}
};
f.setFun(10);
f.getFun();
}
}
// Functional Interface
interface FuntionalInterf {
// abstract method
public abstract void setFun(int x);
// normal method
default void getFun() {
System.out.println("at default method in the Functional Interface");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment