Created
March 2, 2019 18:53
-
-
Save Gzoref/1f2a4f2f4e30c91e1253380200247b47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package OOGreeting; | |
//Objectr Oriented way | |
public class Greeter { | |
public void greet(Greeting greeting) { | |
greeting.perform(); | |
} | |
public static void main(String[] args) { | |
Greeter greeter = new Greeter(); | |
//Greeting helloWorldGreeting = new HelloWorldGreeting(); | |
//Both give same result. Lambda is shorter | |
Greeting lamdaGreeting = () -> System.out.println("Hello Lambda"); | |
Greeting innerClassGreeting = new Greeting() { | |
@Override | |
public void perform() { | |
System.out.println("Hello Inner Class"); | |
} | |
}; | |
greeter.greet(lamdaGreeting); | |
greeter.greet(innerClassGreeting); | |
} | |
} | |
/*interface MyAdd { | |
int add(int a, int b); | |
}*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package OOGreeting; | |
public interface Greeting { | |
public void perform(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package OOGreeting; | |
public class HelloWorldGreeting implements Greeting { | |
@Override | |
public void perform() { | |
System.out.println("Hello Interface"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment