The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java 8 Comparator Example Using Lambda Expressions

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
Java 8 Comparator Example Using Lambda Expressions Posted: Nov 25, 2014 7:12 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: Java 8 Comparator Example Using Lambda Expressions
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
What is the best way to learn lambda expression of Java 8? Of course by using it on your day to day programming task. Since implementing equals, hashcode, compareTo, and compare methods are some of the most common task of a Java developer, it make sense to learn how to use lambda expression to implement custom Comparator and Comparable in Java. One question comes in mind, can we use lambda expression with Comparator, because it's an old interface and may not implement functional interface annotated with @FunctionalInterface annotation? Answer to this question is Yes, you can use lambda expression to implement Comparator and Comparable interface in Java, and not just these two but to implement any interface, which just got one abstract method, remember from Java 8 interface can have non abstract methods as well e.g. default and static methods. That's why lambda expression in Java 8 is known as SAM type, where SAM stands for Single Abstract Method. This was a very important decision Java designers made, which makes it lambdas even more useful. Due to this you can use lambda expressions with Runnable, ActionListener and several other interface which got just one abstract method. By the way, you need not to worry in case of Comparator, because it is made to implement @FunctionalInterface as shown below :
Read more »

Read: Java 8 Comparator Example Using Lambda Expressions

Topic: Don’t repeat expressions in facelets Previous Topic   Next Topic Topic: Three Alternatives for Making Smaller Stories

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use