Java lambda λ

preview_player
Показать описание
java lambda tutorial example explained

#java #lambda #tutorial
Рекомендации по теме
Комментарии
Автор


@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
* known as an anonymous method
* shorter way to write anonymous classes with only one method
*
to use a functional interface or use a pre-defined functional interface
contain only one abstract method
ActionListener, Runnable, (user-defined)
*
Lambda expression can be used in any place where a functional interface is required
to use a lambda expression:
-> {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);


(e) -> System.out.println("This is the first button")

);

myButton2.setBounds(100, 200, 200, 100);


(e) -> System.out.println("This is the second button")

);

this.add(myButton);
this.add(myButton2);

this.setSize(420, 420);
this.setLayout(null);
this.setVisible(true);
}
}

BroCodez
Автор

Bro, you are going to be the reason that i sort my life out and learn java properly finally. Thank you ❤

ChewySmooth
Автор

I tried several manuals on lambda functions in java, it gets complicated quickly.
You, on the other hand, keep it simple, care to explain things like "usually we would code like that", care to provide example with user-defined functions (so it's understandable even for those who haven't used ActionListener before), etc.
You've taught me a thing, thank you very much, Bro.

mikhailreshetnikov
Автор

I love this, so much more elegant for actionListeners than making a long if-else statement or switch

ReBufff
Автор

A lot easier to understand than most (if not all) of other lambda videos!!! As always, you

kaiiemsawat
Автор

Best java series in the whole youtube.. thanku for providing this course for free.

sheikhnaved
Автор

Bro, firstly, I am really grateful for the video that helped me to grasp this topic clearly. Furthermore, I found the explanations and sample codes so benefical. The only thing that I am sad about is that I discovered your channel a bit late. Thanks again for the video bro!

yadigaryusifov
Автор

This was really helpful for me. I am learning lambda expressions and you thoroughly covered a wide section on its uses. Thank you,

dansoto
Автор

Finally someone who can explain Lambda without causing a headache. Thank u Bro!

carlosbernardo
Автор

Thanks a lot for this tutorial, I really like your style comparing to other YouTubers.

Skillet
Автор

Thank You Bro, I learned so much in the last 80 Videos !

hau
Автор

You gained a new subscriber! Ur explanations are exceptional thank you

bruceintrepid
Автор

Hey! Thank you for the simple way of explaining complicated concepts. Well done!

anatolsirbu
Автор

I can see how this can be useful. Great stuff Bro!

sergeyb
Автор

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.

MiauMichigan
Автор

Fantastic video. Thanks for the explanation

bigollie
Автор

OK finally an explanation of Lambda expressions that I can understand! Thank You Bro!

briman
Автор

Thank you, nice explanation with clear examples.

balazsritzinger
Автор

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! =)

oscarjosefsson
Автор

Thanks so much Bro!, Your explanation of Lambdas is much easier to understand than that other youtuber dude with da bald head, that keeps saying: "Meoow!".

richardtriance