SlideShare a Scribd company logo
Extension Methods and Lambdas in Java 82011-03-03Andreas Enbohm
3 mars 2011Sida 2Extension MethodsWhathappenshere?people.sort(#Person.lastName)
Extension MethodsWhatwehave in Java today…Toomuchnoise!Collections.sort(people, new Comparator() {	@Override	public intcompare(Person x, Person y) {returnx.getLastName().compareTo(y.getLastName());	}});3 mars 2011Sida 3
SAM types and LambdasSingle Abstract Method (SAM)3 mars 2011Sida 4Thread th = new Thread(new Runnable() { 		public void run() { doSomeStuff(); doMoreStuff();       } }); //OLD WAYThread th = new Thread(#(){ doSomeStuff(); doMoreStuff(); } )
3 mars 2011Sida 5SAM and Lambdas conversionWith Lambdas and SAM it looks likeCollections.sort(people, #{ Person x, Person y -> 			  x.getLastName().compareTo(y.getLastName()) });//Old way, let’shopewesooncan @Deprecate this codeCollections.sort(people, new Comparator() {	@Override	public intcompare(Person x, Person y) {returnx.getLastName().compareTo(y.getLastName());	}});
EnchancedLibraries (Collections)But it gets evenbetter with EnchancedLibraries3 mars 2011Sida 6//Collections is updated. No need to specify Person x and //Person y, just say ’take a person in the [list] and sort by//last name’ (its implicit that compareToshould be used)Collections.sortBy(people, #{ Person p -> p.getLastName() });
TypeInference…and with somehelp from the compiler…we get TypeInference3 mars 2011Sida 7//No need to specify Person, the compilercan (often) helpus //with this. Compilerintrospectpeople-list via genericsCollections.sortBy(people, #{ p -> p.getLastName() });
MethodReferenceA new feature with Project Lambdas is MethodReferenceswhich gives us…3 mars 2011Sida 8//Methodreferenceallowsus to ’point’ directly to the method//wewant to use in oursorting. Whyuse a particularobject?Collections.sortBy(people, #Person.getLastName );
Extension Methodsand with Extension Methodswefinally get…3 mars 2011Sida 9//Nice, wehavepeople (a List<T>) whichcandosorting. But //wait a minuteList<T> don’thave a sort(…) method… Howdid //this work?people.sortBy( #Person.getLastName);
Extension Methods (DefenderMethods)A way to evolve interfaces WITHOUT breakingbinarybackwardscompatability.Means that wecanadd new methods in an existing interface and the implementingclientsdoes NOT need to implement that method!A reallyneed for updatingaging Collections interface, especiallywhen lambdas and Fork-Join are introduced in JavaThe interface willsupply a default implementationif you do not supplyoneyourself3 mars 2011Sida 10
EnhancedlibrariesProposed Syntax3 mars 2011Sida 11public interface List<T> extends Collection<T> {    public intsize();    // The rest of the existing List methods    extensionvoid sort(List<T> list) default  Collections.<T>sort;}
3 mars 2011Sida 12Extension MethodsQuestions?people.eat(#Senadin.cake)
Ad

More Related Content

What's hot (19)

Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
BG Java EE Course
 
C Omega
C OmegaC Omega
C Omega
iradarji
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
Fahd Allebdi
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and Algorithms
SNEHAL MASNE
 
Incremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher QueriesIncremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher Queries
Gábor Szárnyas
 
Just Kotlin
Just KotlinJust Kotlin
Just Kotlin
Ismail Habib Muhammad
 
Doubly Link List
Doubly Link ListDoubly Link List
Doubly Link List
Kashif Memon
 
Functional Concepts
Functional ConceptsFunctional Concepts
Functional Concepts
Michal Píše
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Progress Report 20091009
Progress Report 20091009Progress Report 20091009
Progress Report 20091009
xoanon
 
linked list
linked list linked list
linked list
Mohaimin Rahat
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
Alberto Labarga
 
TRank ISWC2013
TRank ISWC2013TRank ISWC2013
TRank ISWC2013
eXascale Infolab
 
Duplicate Detection in Hierarchical Data Using XPath
Duplicate Detection in Hierarchical Data Using XPathDuplicate Detection in Hierarchical Data Using XPath
Duplicate Detection in Hierarchical Data Using XPath
iosrjce
 
Combining Inverted Indices and Structured Search for Ad-hoc Object Retrieval
Combining Inverted Indices and Structured Search for  Ad-hoc Object RetrievalCombining Inverted Indices and Structured Search for  Ad-hoc Object Retrieval
Combining Inverted Indices and Structured Search for Ad-hoc Object Retrieval
eXascale Infolab
 
Compiler design
Compiler designCompiler design
Compiler design
PriyadharshiniVS
 
Basic Tutorial of Association Mapping by Avjinder Kaler
Basic Tutorial of Association Mapping by Avjinder KalerBasic Tutorial of Association Mapping by Avjinder Kaler
Basic Tutorial of Association Mapping by Avjinder Kaler
Avjinder (Avi) Kaler
 
Check my answer to pass data from one webform to the next, you ca
 Check my answer to pass data from one webform to the next, you ca Check my answer to pass data from one webform to the next, you ca
Check my answer to pass data from one webform to the next, you ca
licservernoida
 
ADT STACK and Queues
ADT STACK and QueuesADT STACK and Queues
ADT STACK and Queues
BHARATH KUMAR
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
Fahd Allebdi
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and Algorithms
SNEHAL MASNE
 
Incremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher QueriesIncremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher Queries
Gábor Szárnyas
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Progress Report 20091009
Progress Report 20091009Progress Report 20091009
Progress Report 20091009
xoanon
 
Duplicate Detection in Hierarchical Data Using XPath
Duplicate Detection in Hierarchical Data Using XPathDuplicate Detection in Hierarchical Data Using XPath
Duplicate Detection in Hierarchical Data Using XPath
iosrjce
 
Combining Inverted Indices and Structured Search for Ad-hoc Object Retrieval
Combining Inverted Indices and Structured Search for  Ad-hoc Object RetrievalCombining Inverted Indices and Structured Search for  Ad-hoc Object Retrieval
Combining Inverted Indices and Structured Search for Ad-hoc Object Retrieval
eXascale Infolab
 
Basic Tutorial of Association Mapping by Avjinder Kaler
Basic Tutorial of Association Mapping by Avjinder KalerBasic Tutorial of Association Mapping by Avjinder Kaler
Basic Tutorial of Association Mapping by Avjinder Kaler
Avjinder (Avi) Kaler
 
Check my answer to pass data from one webform to the next, you ca
 Check my answer to pass data from one webform to the next, you ca Check my answer to pass data from one webform to the next, you ca
Check my answer to pass data from one webform to the next, you ca
licservernoida
 
ADT STACK and Queues
ADT STACK and QueuesADT STACK and Queues
ADT STACK and Queues
BHARATH KUMAR
 

Viewers also liked (8)

Software Craftsmanship
Software CraftsmanshipSoftware Craftsmanship
Software Craftsmanship
Andreas Enbohm
 
BDD Short Introduction
BDD Short IntroductionBDD Short Introduction
BDD Short Introduction
Andreas Enbohm
 
Scala
ScalaScala
Scala
Andreas Enbohm
 
Project Lambda - Closures after all?
Project Lambda - Closures after all?Project Lambda - Closures after all?
Project Lambda - Closures after all?
Andreas Enbohm
 
Behavior-driven Development and Lambdaj
Behavior-driven Development and LambdajBehavior-driven Development and Lambdaj
Behavior-driven Development and Lambdaj
Andreas Enbohm
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 Features
Andreas Enbohm
 
Hybrid Applications
Hybrid ApplicationsHybrid Applications
Hybrid Applications
Andreas Enbohm
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
Andreas Enbohm
 
Software Craftsmanship
Software CraftsmanshipSoftware Craftsmanship
Software Craftsmanship
Andreas Enbohm
 
BDD Short Introduction
BDD Short IntroductionBDD Short Introduction
BDD Short Introduction
Andreas Enbohm
 
Project Lambda - Closures after all?
Project Lambda - Closures after all?Project Lambda - Closures after all?
Project Lambda - Closures after all?
Andreas Enbohm
 
Behavior-driven Development and Lambdaj
Behavior-driven Development and LambdajBehavior-driven Development and Lambdaj
Behavior-driven Development and Lambdaj
Andreas Enbohm
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 Features
Andreas Enbohm
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
Andreas Enbohm
 
Ad

Similar to Java Extension Methods (20)

Lambdas: Myths and Mistakes
Lambdas: Myths and MistakesLambdas: Myths and Mistakes
Lambdas: Myths and Mistakes
RichardWarburton
 
Data Science Academy Student Demo day--Michael blecher,the importance of clea...
Data Science Academy Student Demo day--Michael blecher,the importance of clea...Data Science Academy Student Demo day--Michael blecher,the importance of clea...
Data Science Academy Student Demo day--Michael blecher,the importance of clea...
Vivian S. Zhang
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
karymadelaneyrenne19
 
FUNctional Programming in Java 8
FUNctional Programming in Java 8FUNctional Programming in Java 8
FUNctional Programming in Java 8
Richard Walker
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
jillisacebi75827
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5
ecomputernotes
 
Java 8 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
Mark Harrison
 
Computer notes - Josephus Problem
Computer notes - Josephus ProblemComputer notes - Josephus Problem
Computer notes - Josephus Problem
ecomputernotes
 
Java 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually useJava 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually use
Sharon Rozinsky
 
Invitation to Scala
Invitation to ScalaInvitation to Scala
Invitation to Scala
Michael Bar-Sinai
 
Roberto Trasarti PhD Thesis
Roberto Trasarti PhD ThesisRoberto Trasarti PhD Thesis
Roberto Trasarti PhD Thesis
Roberto Trasarti
 
Graphql
GraphqlGraphql
Graphql
Neven Rakonić
 
Lab 1 Recursion  Introduction   Tracery (tracery.io.docx
Lab 1 Recursion  Introduction   Tracery (tracery.io.docxLab 1 Recursion  Introduction   Tracery (tracery.io.docx
Lab 1 Recursion  Introduction   Tracery (tracery.io.docx
smile790243
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
Shahzad
 
myEquivalents, aka a new cross-reference service
myEquivalents, aka a new cross-reference servicemyEquivalents, aka a new cross-reference service
myEquivalents, aka a new cross-reference service
Rothamsted Research, UK
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2
Philip Schwarz
 
Tolog Updates
Tolog UpdatesTolog Updates
Tolog Updates
Lars Marius Garshol
 
computer notes - Circular list
computer notes - Circular listcomputer notes - Circular list
computer notes - Circular list
ecomputernotes
 
Introduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing EnvironmentIntroduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing Environment
izahn
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)
mussawir20
 
Lambdas: Myths and Mistakes
Lambdas: Myths and MistakesLambdas: Myths and Mistakes
Lambdas: Myths and Mistakes
RichardWarburton
 
Data Science Academy Student Demo day--Michael blecher,the importance of clea...
Data Science Academy Student Demo day--Michael blecher,the importance of clea...Data Science Academy Student Demo day--Michael blecher,the importance of clea...
Data Science Academy Student Demo day--Michael blecher,the importance of clea...
Vivian S. Zhang
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
karymadelaneyrenne19
 
FUNctional Programming in Java 8
FUNctional Programming in Java 8FUNctional Programming in Java 8
FUNctional Programming in Java 8
Richard Walker
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
jillisacebi75827
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5
ecomputernotes
 
Computer notes - Josephus Problem
Computer notes - Josephus ProblemComputer notes - Josephus Problem
Computer notes - Josephus Problem
ecomputernotes
 
Java 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually useJava 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually use
Sharon Rozinsky
 
Roberto Trasarti PhD Thesis
Roberto Trasarti PhD ThesisRoberto Trasarti PhD Thesis
Roberto Trasarti PhD Thesis
Roberto Trasarti
 
Lab 1 Recursion  Introduction   Tracery (tracery.io.docx
Lab 1 Recursion  Introduction   Tracery (tracery.io.docxLab 1 Recursion  Introduction   Tracery (tracery.io.docx
Lab 1 Recursion  Introduction   Tracery (tracery.io.docx
smile790243
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
Shahzad
 
myEquivalents, aka a new cross-reference service
myEquivalents, aka a new cross-reference servicemyEquivalents, aka a new cross-reference service
myEquivalents, aka a new cross-reference service
Rothamsted Research, UK
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2
Philip Schwarz
 
computer notes - Circular list
computer notes - Circular listcomputer notes - Circular list
computer notes - Circular list
ecomputernotes
 
Introduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing EnvironmentIntroduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing Environment
izahn
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)
mussawir20
 
Ad

Recently uploaded (20)

Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 

Java Extension Methods

  • 1. Extension Methods and Lambdas in Java 82011-03-03Andreas Enbohm
  • 2. 3 mars 2011Sida 2Extension MethodsWhathappenshere?people.sort(#Person.lastName)
  • 3. Extension MethodsWhatwehave in Java today…Toomuchnoise!Collections.sort(people, new Comparator() { @Override public intcompare(Person x, Person y) {returnx.getLastName().compareTo(y.getLastName()); }});3 mars 2011Sida 3
  • 4. SAM types and LambdasSingle Abstract Method (SAM)3 mars 2011Sida 4Thread th = new Thread(new Runnable() { public void run() { doSomeStuff(); doMoreStuff(); } }); //OLD WAYThread th = new Thread(#(){ doSomeStuff(); doMoreStuff(); } )
  • 5. 3 mars 2011Sida 5SAM and Lambdas conversionWith Lambdas and SAM it looks likeCollections.sort(people, #{ Person x, Person y -> x.getLastName().compareTo(y.getLastName()) });//Old way, let’shopewesooncan @Deprecate this codeCollections.sort(people, new Comparator() { @Override public intcompare(Person x, Person y) {returnx.getLastName().compareTo(y.getLastName()); }});
  • 6. EnchancedLibraries (Collections)But it gets evenbetter with EnchancedLibraries3 mars 2011Sida 6//Collections is updated. No need to specify Person x and //Person y, just say ’take a person in the [list] and sort by//last name’ (its implicit that compareToshould be used)Collections.sortBy(people, #{ Person p -> p.getLastName() });
  • 7. TypeInference…and with somehelp from the compiler…we get TypeInference3 mars 2011Sida 7//No need to specify Person, the compilercan (often) helpus //with this. Compilerintrospectpeople-list via genericsCollections.sortBy(people, #{ p -> p.getLastName() });
  • 8. MethodReferenceA new feature with Project Lambdas is MethodReferenceswhich gives us…3 mars 2011Sida 8//Methodreferenceallowsus to ’point’ directly to the method//wewant to use in oursorting. Whyuse a particularobject?Collections.sortBy(people, #Person.getLastName );
  • 9. Extension Methodsand with Extension Methodswefinally get…3 mars 2011Sida 9//Nice, wehavepeople (a List<T>) whichcandosorting. But //wait a minuteList<T> don’thave a sort(…) method… Howdid //this work?people.sortBy( #Person.getLastName);
  • 10. Extension Methods (DefenderMethods)A way to evolve interfaces WITHOUT breakingbinarybackwardscompatability.Means that wecanadd new methods in an existing interface and the implementingclientsdoes NOT need to implement that method!A reallyneed for updatingaging Collections interface, especiallywhen lambdas and Fork-Join are introduced in JavaThe interface willsupply a default implementationif you do not supplyoneyourself3 mars 2011Sida 10
  • 11. EnhancedlibrariesProposed Syntax3 mars 2011Sida 11public interface List<T> extends Collection<T> { public intsize(); // The rest of the existing List methods extensionvoid sort(List<T> list) default Collections.<T>sort;}
  • 12. 3 mars 2011Sida 12Extension MethodsQuestions?people.eat(#Senadin.cake)