Java lambda λ

Java lambda λ

Bro Code

3 года назад

88,269 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Bro Code
Bro Code - 19.06.2020 01:28

/************************************************************************************
@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);
}
}
//************************************************************************************

Ответить
Adriano Raposo
Adriano Raposo - 18.10.2023 16:03

Good!

Ответить
XxG3fAllx X
XxG3fAllx X - 25.07.2023 23:06

Why ist the abstract method not signed as abstract?

Ответить
Tony
Tony - 24.06.2023 14:59

Man why are you doing this for free?

Ответить
Mr. Loser
Mr. Loser - 18.06.2023 12:09

Thanks!

Ответить
Ron-lukas Gottschalk
Ron-lukas Gottschalk - 15.06.2023 00:45

helpful as always!

Ответить
Tekniko's Cave
Tekniko's Cave - 08.03.2023 08:09

Seems so pointless, like why even bother doing it this way.

Ответить
Gloria
Gloria - 03.03.2023 02:04

thanks Bro! I finally understand what is the Lambda-expression!

Ответить
JuniorMR
JuniorMR - 26.02.2023 12:15

The thing i most like in bro is that he always goes straight to the point

Ответить
Oscar Josefsson
Oscar Josefsson - 04.02.2023 22:11

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

Ответить
F GJ
F GJ - 15.01.2023 20:53

Bro! you da best.

Ответить
carlos bernardo
carlos bernardo - 13.01.2023 17:53

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

Ответить
Ghaith Thamer
Ghaith Thamer - 04.01.2023 02:28

Thanks

Ответить
Balázs Ritzinger
Balázs Ritzinger - 01.01.2023 04:28

Thank you, nice explanation with clear examples.

Ответить
Antonio B.
Antonio B. - 23.12.2022 17:14

Thanks for leaving your code in the comments, that with your video are going to make things so much easier 👌

Ответить
BurninVinyl
BurninVinyl - 21.12.2022 17:34

Lambalicious

Ответить
Anatol Sirbu
Anatol Sirbu - 10.12.2022 10:18

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

Ответить
Amar Boparai
Amar Boparai - 09.12.2022 16:24

The button initially said "MY BUTT..."

Ответить
Connie
Connie - 01.11.2022 10:12

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.

Ответить
oLunatiko
oLunatiko - 30.10.2022 05:15

Great vid, bro!

Ответить
Bruce Intrepid
Bruce Intrepid - 26.10.2022 13:24

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

Ответить
kai iemsawat
kai iemsawat - 25.09.2022 02:09

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

Ответить
Ania Nowak
Ania Nowak - 24.09.2022 14:11

Hi :)

Ответить
dan soto
dan soto - 16.09.2022 21:19

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

Ответить
Manuel Gonzalez Palafox
Manuel Gonzalez Palafox - 14.09.2022 23:02

Ly bro 10

Ответить
Dima Khodosevich
Dima Khodosevich - 06.08.2022 01:34

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?

Ответить
Fabian Blaga
Fabian Blaga - 29.07.2022 13:47

thaaanks bro! :D

Ответить
Daxter T. Snickers
Daxter T. Snickers - 21.07.2022 14:52

I like my coffee like I like my women.
Not yelling at me.

Ответить
Zoran Milosavljevic
Zoran Milosavljevic - 20.07.2022 13:59

Great Java tutorial, thank you!

Ответить
Syed Nizam
Syed Nizam - 04.07.2022 06:24

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?

Ответить
LodeStar YT
LodeStar YT - 25.06.2022 16:55

my BUTT....

Ответить
Fernando Bautista
Fernando Bautista - 18.06.2022 04:47

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

Ответить
Kalyan Kumar
Kalyan Kumar - 09.06.2022 18:14

Very clear understanding!good .

Ответить
yakut soraya
yakut soraya - 23.05.2022 18:27

Your voice force me coding. <3

Ответить
Code Zero
Code Zero - 21.05.2022 04:49

.

Ответить
Kalyan Kumar
Kalyan Kumar - 20.05.2022 17:12

Good bro!

Ответить
Honored Egg
Honored Egg - 03.05.2022 01:21

82th. Thank you, ma Bro Sensei

Ответить
zhenni qi
zhenni qi - 02.05.2022 16:24

amazing.

Ответить
zhenni qi
zhenni qi - 02.05.2022 15:44

Thank you.谢谢。

Ответить
briman
briman - 24.04.2022 22:13

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

Ответить
ballin
ballin - 21.04.2022 02:39

GOAT.

Ответить
Gabriel Micillo
Gabriel Micillo - 20.04.2022 15:17

excellent

Ответить
İbrahim Yılmaz
İbrahim Yılmaz - 15.04.2022 21:22

thanks bro

Ответить
Mihir Malladi
Mihir Malladi - 08.04.2022 04:58

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?

Ответить
Igor Santana
Igor Santana - 23.03.2022 22:57

Thank you Bro!

Ответить
henri
henri - 15.03.2022 19:32

In the second example how can you just introduce myFrame and never use it? :(
(in public class Main)

Ответить
Топчий Даниил
Топчий Даниил - 26.02.2022 08:30

Thank you a lot

Ответить
Hippie Stereo
Hippie Stereo - 14.02.2022 22:43

Bro rocks

Ответить