Комментарии:
/************************************************************************************
@FunctionalInterface
public interface MyInterface {
public void message(String name,char symbol);
}
//******************************* Example 1 **************************************
public class Main {
public static void main(String[] args) {
/* lambda expression = feature for Java 8 and above
* also known as an anonymous method
* a shorter way to write anonymous classes with only one method
*
* need to use a functional interface or use a pre-defined functional interface
* they contain only one abstract method
* ex. ActionListener, Runnable, (user-defined)
*
* A Lambda expression can be used in any place where a functional interface is required
* How to use a lambda expression:
* (arguments) -> {statement/s}
*/
String name = "Bro";
char symbol = '!';
MyInterface myInterface = (x,y) -> {
System.out.println("Heello World!");
System.out.println("It is a nice day "+x+y);
};
MyInterface myInterface2 = (x,y) -> {
System.out.println("Hello "+x+y);
};
myInterface.message(name,symbol);
myInterface2.message(name,symbol);
}
}
//******************************* Example 2 **************************************
public class Main {
public static void main(String[] args) {
MyFrame myFrame = new MyFrame();
}
}
//************************************************************************************
import java.awt.event.*;
import javax.swing.*;
public class MyFrame extends JFrame{
JButton myButton = new JButton("MY BUTTON 1");
JButton myButton2 = new JButton("MY BUTTON 2");
MyFrame(){
myButton.setBounds(100, 100, 200, 100);
myButton.addActionListener(
(e) -> System.out.println("This is the first button")
);
myButton2.setBounds(100, 200, 200, 100);
myButton2.addActionListener(
(e) -> System.out.println("This is the second button")
);
this.add(myButton);
this.add(myButton2);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(420, 420);
this.setLayout(null);
this.setVisible(true);
}
}
//************************************************************************************
Good!
ОтветитьWhy ist the abstract method not signed as abstract?
ОтветитьMan why are you doing this for free?
ОтветитьThanks!
Ответитьhelpful as always!
ОтветитьSeems so pointless, like why even bother doing it this way.
Ответитьthanks Bro! I finally understand what is the Lambda-expression!
ОтветитьThe thing i most like in bro is that he always goes straight to the point
ОтветитьYeah, I looked at another tutorial first and I did not understand anything.
And then you came along and explained it in a much better way!
Like someone else pointed out, it was really useful that you showed how the anonymous inner class that we are replacing would have looked!
That really makes it a lot easier to understand what is going on! =)
Bro! you da best.
ОтветитьFinally someone who can explain Lambda without causing a headache. Thank u Bro!
ОтветитьThanks
ОтветитьThank you, nice explanation with clear examples.
ОтветитьThanks for leaving your code in the comments, that with your video are going to make things so much easier 👌
ОтветитьLambalicious
ОтветитьHey! Thank you for the simple way of explaining complicated concepts. Well done!
ОтветитьThank you! This is easy enough for me to undestand as a beginner. Other tutorials go to fast or are too advanced for my level.
ОтветитьGreat vid, bro!
ОтветитьYou gained a new subscriber! Ur explanations are exceptional thank you
ОтветитьA lot easier to understand than most (if not all) of other lambda videos!!! As always, you rock!!!!!
ОтветитьHi :)
ОтветитьThis was really helpful for me. I am learning lambda expressions and you thoroughly covered a wide section on its uses. Thank you,
ОтветитьLy bro 10
ОтветитьI am soryy, but i am stuck, when you add actionListener and use lambda expression, you pass "e" as an argument of your method, but this "e" you didn't assigned nowhere, so how does it works?
Ответитьthaaanks bro! :D
ОтветитьI like my coffee like I like my women.
Not yelling at me.
Great Java tutorial, thank you!
ОтветитьHi Bro, You have mentioned that the Functional Interfaces have only one abstract method. How many different kinds of interfaces do we have in Java?
Ответитьmy BUTT....
ОтветитьI like all yours video about java(my listening isn't good) but I can understand all you say ...thank for all ...a hug from Rep Dom
ОтветитьVery clear understanding!good .
ОтветитьYour voice force me coding. <3
Ответить.
ОтветитьGood bro!
Ответитьamazing.
ОтветитьThank you.谢谢。
ОтветитьOK finally an explanation of Lambda expressions that I can understand! Thank You Bro!
ОтветитьGOAT.
Ответитьexcellent
Ответитьthanks bro
ОтветитьSo lambdas are when you have 2 classes, one of them with a void method, and the other one with the lambda. The one with the lambda defines what the void method does and calls it?
ОтветитьThank you Bro!
ОтветитьIn the second example how can you just introduce myFrame and never use it? :(
(in public class Main)
Thank you a lot
ОтветитьBro rocks
Ответить