How to write Lambda Expressions in Java 8 Video

Поділитися
Вставка
  • Опубліковано 19 січ 2025

КОМЕНТАРІ • 10

  • @saiprasannach2488
    @saiprasannach2488 4 роки тому

    Great explanation

  • @satishsubhashish
    @satishsubhashish 6 років тому

    Really a great lecture. I had lots of confusion in lambda and now I got a great understanding.

  • @biswaroy1869
    @biswaroy1869 5 років тому

    I've a question on method reference. To sort the names at line 14 you've used lambda:
    Collections.sort(persons, (o1, o2) -> o1.getName().compareTo(o2.getName());
    How can we represent it in method reference. I understood how to do it using Comparator.comparing(Person::getName) as comparing takes Function. But how can we use method reference for compareTo ? I tried the following but throws exception:
    Collections.sort(persons, String::compareTo);
    Collections.sort(persons, Person::getName);

  • @somendraprakash979
    @somendraprakash979 6 років тому

    how on the earth can you create a thread by calling run() method ??? r1.run() , please expain

    • @jvsnyc
      @jvsnyc 4 роки тому

      You actually do NOT create a thread. What he did there runs in the same main thread. I used to think it was useless, but i've seen some very neat timer code that would time different "Runnable" items, that was quite useful. So there are at least some uses of "Runnable" besides feeding them into a new Thread construction.

  • @ayushman_sr
    @ayushman_sr 6 років тому

    Good

  • @birkhansonkan4236
    @birkhansonkan4236 7 років тому +1

    where is the link?

    • @JesseQuickEats
      @JesseQuickEats 7 років тому

      github.com/freetipscentral/java8-lambdaExpressionExample/tree/master/LambdaExpressions/src/com/freetipscentral

  • @JesseQuickEats
    @JesseQuickEats 7 років тому

    Link to his github -
    github.com/freetipscentral/java8-lambdaExpressionExample/tree/master/LambdaExpressions/src/com/freetipscentral

  • @jvsnyc
    @jvsnyc 4 роки тому

    Purists will remind people that lambda expressions are really not just a shortcut to create anonymous classes in a simple and easy-to-read manner. As you have shown, they can only implement exactly one abstract method, unlike an anonymous class. They can't have "instance initializer" code like anonymous classes can. No anonymous class is produced on disk at compile time, nor loaded at run time, nor instantiated and destroyed. For all those reasons and also the fact that it doesn't change the meaning of the "this" pointer from the surrounding code, they are distinct from anonymous class instances.
    While it isn't terrible at the beginning to remember "lambda expressions are an easier, lighter alternative to implementing anonymous class instances for special cases where they can work", thinking that they *are* anonymous inner classes is not really correct.