Real world example to use Functional Interface in Java
I know a functional interface means you can have exactly/only 1 abstract method with more than 1 default method(s) but I am wondering to relate it with a real-world example/Situation to use functional interface in Java.
Could you list down a valid situation/example?
Thanks in advance!
java java-8 functional-interface lightweight-stream-api
add a comment |
I know a functional interface means you can have exactly/only 1 abstract method with more than 1 default method(s) but I am wondering to relate it with a real-world example/Situation to use functional interface in Java.
Could you list down a valid situation/example?
Thanks in advance!
java java-8 functional-interface lightweight-stream-api
1
Lambda are implementations of Functional interface...so either implicitly (by a compiler or at runtime) or explicitly (by code...assignment) they are going to be used. Practical example is a Predicate usage across code for filtering.
– Amit
40 mins ago
add a comment |
I know a functional interface means you can have exactly/only 1 abstract method with more than 1 default method(s) but I am wondering to relate it with a real-world example/Situation to use functional interface in Java.
Could you list down a valid situation/example?
Thanks in advance!
java java-8 functional-interface lightweight-stream-api
I know a functional interface means you can have exactly/only 1 abstract method with more than 1 default method(s) but I am wondering to relate it with a real-world example/Situation to use functional interface in Java.
Could you list down a valid situation/example?
Thanks in advance!
java java-8 functional-interface lightweight-stream-api
java java-8 functional-interface lightweight-stream-api
edited 1 hour ago
nullpointer
42.5k1090175
42.5k1090175
asked 1 hour ago
Arun Kumar
2,53992555
2,53992555
1
Lambda are implementations of Functional interface...so either implicitly (by a compiler or at runtime) or explicitly (by code...assignment) they are going to be used. Practical example is a Predicate usage across code for filtering.
– Amit
40 mins ago
add a comment |
1
Lambda are implementations of Functional interface...so either implicitly (by a compiler or at runtime) or explicitly (by code...assignment) they are going to be used. Practical example is a Predicate usage across code for filtering.
– Amit
40 mins ago
1
1
Lambda are implementations of Functional interface...so either implicitly (by a compiler or at runtime) or explicitly (by code...assignment) they are going to be used. Practical example is a Predicate usage across code for filtering.
– Amit
40 mins ago
Lambda are implementations of Functional interface...so either implicitly (by a compiler or at runtime) or explicitly (by code...assignment) they are going to be used. Practical example is a Predicate usage across code for filtering.
– Amit
40 mins ago
add a comment |
5 Answers
5
active
oldest
votes
One of the primary use that they've provided is that the instances of functional interfaces can be created with lambda expressions and method references as well as using a constructor at the same time. For example, a functional interface Sample
defined as:
@FunctionalInterface
public interface Sample {
void ab();
}
can be instantiated in as simple as a single line of code as :
Sample sample = () -> System.out.println("ab called");
and then called wherever required as:
sample.ab();
I would further quote the Javadoc from the java.util.function
package:
Functional interfaces can provide a target type in multiple contexts,
such as assignment context, method invocation, or cast context:
// Assignment context
Predicate<String> p = String::isEmpty;
// Method invocation context
stream.filter(e -> e.getSize() > 10)...
// Cast context
stream.map((ToIntFunction) e -> e.getSize())...
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
First of all annotation @FunctionalInterface
is used by Java's built-in functional interfaces Predicate
,Function
,Consumer
, etc...
From the other hand you may want to create your custom one like the following:
@FunctionalInterface
public interface ThrowingConsumer<T> {
void accept(T t) throws CustomException;
}
Then you can use it as a method parameter:
public <T, R> void doSomething(T value, ThrowingConsumer<T, R> consumer) {
// ...
}
And then call it like this:
doSomething(someValue, this::customConsumerMethodThrowingAnException);
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
Interfaces which are marked with FunctionalInterface
are guaranteed to be applicable in contexts where a lambda expression with appropriate parameter and return types is expected. Besides that, they have no usage. There might be some optimizations, but in all cases it doesnt matter
add a comment |
Lambdas are implementations of Functional interface...so either implicitly (by a compiler or at run-time) or explicitly (by code...assignment) they are going to be used. Practical example is
- Predicate : usage across code for filtering.
- Functions : Map.computeIfAbsent("xxx", s -> s.length());
- BiFunction : salaries.replaceAll((name, oldValue) -> name.equals("Freddy") ? oldValue : oldValue + 10000);
- Consumers : List.forEach(name -> System.out.println("Hello, " + name));
add a comment |
We've always had functional interfaces before JDK8 but no lambdas, method references etc.
As of JDK8, they provide a target type for lambda expressions, method references and in turn, have better readability and more compact code.
Example, prior to Java-8 if you wanted to provide some logic that will be executed each time a Button
component is clicked you'd do:
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
This is bulky, hard to read and not compact enough. because EventHandler
is by definition a functional interface i.e. it has a SAM
as of jdk8 you can now do:
btn.setOnAction(event -> System.out.println("Hello World!"));
You only see the part of the code you care about i.e. the logic to be executed when the button is clicked.
Further, due to the fact that we can use functional interfaces as target types for lambda expressions & methods references, this would be useful when:
- passing a comparator to a sort method e.g.
List.sort
,Stream.sorted
,Collections.sort
etc. - passing a block of code to run a task in a separate thread
etc...
while keeping the code readable, compact and concise.
Functional interfaces are used extensively in the Java-stream API.
There's no reason for you to create your own functional interface except there's not one that meets your requirements from java.util.function
or the name of the functional interface is not as readable so thus you may create your own.
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54004144%2freal-world-example-to-use-functional-interface-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
One of the primary use that they've provided is that the instances of functional interfaces can be created with lambda expressions and method references as well as using a constructor at the same time. For example, a functional interface Sample
defined as:
@FunctionalInterface
public interface Sample {
void ab();
}
can be instantiated in as simple as a single line of code as :
Sample sample = () -> System.out.println("ab called");
and then called wherever required as:
sample.ab();
I would further quote the Javadoc from the java.util.function
package:
Functional interfaces can provide a target type in multiple contexts,
such as assignment context, method invocation, or cast context:
// Assignment context
Predicate<String> p = String::isEmpty;
// Method invocation context
stream.filter(e -> e.getSize() > 10)...
// Cast context
stream.map((ToIntFunction) e -> e.getSize())...
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
One of the primary use that they've provided is that the instances of functional interfaces can be created with lambda expressions and method references as well as using a constructor at the same time. For example, a functional interface Sample
defined as:
@FunctionalInterface
public interface Sample {
void ab();
}
can be instantiated in as simple as a single line of code as :
Sample sample = () -> System.out.println("ab called");
and then called wherever required as:
sample.ab();
I would further quote the Javadoc from the java.util.function
package:
Functional interfaces can provide a target type in multiple contexts,
such as assignment context, method invocation, or cast context:
// Assignment context
Predicate<String> p = String::isEmpty;
// Method invocation context
stream.filter(e -> e.getSize() > 10)...
// Cast context
stream.map((ToIntFunction) e -> e.getSize())...
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
One of the primary use that they've provided is that the instances of functional interfaces can be created with lambda expressions and method references as well as using a constructor at the same time. For example, a functional interface Sample
defined as:
@FunctionalInterface
public interface Sample {
void ab();
}
can be instantiated in as simple as a single line of code as :
Sample sample = () -> System.out.println("ab called");
and then called wherever required as:
sample.ab();
I would further quote the Javadoc from the java.util.function
package:
Functional interfaces can provide a target type in multiple contexts,
such as assignment context, method invocation, or cast context:
// Assignment context
Predicate<String> p = String::isEmpty;
// Method invocation context
stream.filter(e -> e.getSize() > 10)...
// Cast context
stream.map((ToIntFunction) e -> e.getSize())...
One of the primary use that they've provided is that the instances of functional interfaces can be created with lambda expressions and method references as well as using a constructor at the same time. For example, a functional interface Sample
defined as:
@FunctionalInterface
public interface Sample {
void ab();
}
can be instantiated in as simple as a single line of code as :
Sample sample = () -> System.out.println("ab called");
and then called wherever required as:
sample.ab();
I would further quote the Javadoc from the java.util.function
package:
Functional interfaces can provide a target type in multiple contexts,
such as assignment context, method invocation, or cast context:
// Assignment context
Predicate<String> p = String::isEmpty;
// Method invocation context
stream.filter(e -> e.getSize() > 10)...
// Cast context
stream.map((ToIntFunction) e -> e.getSize())...
edited 22 mins ago
answered 1 hour ago
nullpointer
42.5k1090175
42.5k1090175
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
Could you add a comment about
@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not @FunctionalInterface
...– Boris the Spider
4 mins ago
Could you add a comment about
@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not @FunctionalInterface
...– Boris the Spider
4 mins ago
add a comment |
First of all annotation @FunctionalInterface
is used by Java's built-in functional interfaces Predicate
,Function
,Consumer
, etc...
From the other hand you may want to create your custom one like the following:
@FunctionalInterface
public interface ThrowingConsumer<T> {
void accept(T t) throws CustomException;
}
Then you can use it as a method parameter:
public <T, R> void doSomething(T value, ThrowingConsumer<T, R> consumer) {
// ...
}
And then call it like this:
doSomething(someValue, this::customConsumerMethodThrowingAnException);
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
First of all annotation @FunctionalInterface
is used by Java's built-in functional interfaces Predicate
,Function
,Consumer
, etc...
From the other hand you may want to create your custom one like the following:
@FunctionalInterface
public interface ThrowingConsumer<T> {
void accept(T t) throws CustomException;
}
Then you can use it as a method parameter:
public <T, R> void doSomething(T value, ThrowingConsumer<T, R> consumer) {
// ...
}
And then call it like this:
doSomething(someValue, this::customConsumerMethodThrowingAnException);
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
First of all annotation @FunctionalInterface
is used by Java's built-in functional interfaces Predicate
,Function
,Consumer
, etc...
From the other hand you may want to create your custom one like the following:
@FunctionalInterface
public interface ThrowingConsumer<T> {
void accept(T t) throws CustomException;
}
Then you can use it as a method parameter:
public <T, R> void doSomething(T value, ThrowingConsumer<T, R> consumer) {
// ...
}
And then call it like this:
doSomething(someValue, this::customConsumerMethodThrowingAnException);
First of all annotation @FunctionalInterface
is used by Java's built-in functional interfaces Predicate
,Function
,Consumer
, etc...
From the other hand you may want to create your custom one like the following:
@FunctionalInterface
public interface ThrowingConsumer<T> {
void accept(T t) throws CustomException;
}
Then you can use it as a method parameter:
public <T, R> void doSomething(T value, ThrowingConsumer<T, R> consumer) {
// ...
}
And then call it like this:
doSomething(someValue, this::customConsumerMethodThrowingAnException);
edited 1 hour ago
answered 1 hour ago
ETO
1,708321
1,708321
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
Could you add a comment about
@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not @FunctionalInterface
...– Boris the Spider
4 mins ago
Could you add a comment about
@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not @FunctionalInterface
...– Boris the Spider
4 mins ago
add a comment |
Interfaces which are marked with FunctionalInterface
are guaranteed to be applicable in contexts where a lambda expression with appropriate parameter and return types is expected. Besides that, they have no usage. There might be some optimizations, but in all cases it doesnt matter
add a comment |
Interfaces which are marked with FunctionalInterface
are guaranteed to be applicable in contexts where a lambda expression with appropriate parameter and return types is expected. Besides that, they have no usage. There might be some optimizations, but in all cases it doesnt matter
add a comment |
Interfaces which are marked with FunctionalInterface
are guaranteed to be applicable in contexts where a lambda expression with appropriate parameter and return types is expected. Besides that, they have no usage. There might be some optimizations, but in all cases it doesnt matter
Interfaces which are marked with FunctionalInterface
are guaranteed to be applicable in contexts where a lambda expression with appropriate parameter and return types is expected. Besides that, they have no usage. There might be some optimizations, but in all cases it doesnt matter
answered 1 hour ago
NEGR KITAEC
707
707
add a comment |
add a comment |
Lambdas are implementations of Functional interface...so either implicitly (by a compiler or at run-time) or explicitly (by code...assignment) they are going to be used. Practical example is
- Predicate : usage across code for filtering.
- Functions : Map.computeIfAbsent("xxx", s -> s.length());
- BiFunction : salaries.replaceAll((name, oldValue) -> name.equals("Freddy") ? oldValue : oldValue + 10000);
- Consumers : List.forEach(name -> System.out.println("Hello, " + name));
add a comment |
Lambdas are implementations of Functional interface...so either implicitly (by a compiler or at run-time) or explicitly (by code...assignment) they are going to be used. Practical example is
- Predicate : usage across code for filtering.
- Functions : Map.computeIfAbsent("xxx", s -> s.length());
- BiFunction : salaries.replaceAll((name, oldValue) -> name.equals("Freddy") ? oldValue : oldValue + 10000);
- Consumers : List.forEach(name -> System.out.println("Hello, " + name));
add a comment |
Lambdas are implementations of Functional interface...so either implicitly (by a compiler or at run-time) or explicitly (by code...assignment) they are going to be used. Practical example is
- Predicate : usage across code for filtering.
- Functions : Map.computeIfAbsent("xxx", s -> s.length());
- BiFunction : salaries.replaceAll((name, oldValue) -> name.equals("Freddy") ? oldValue : oldValue + 10000);
- Consumers : List.forEach(name -> System.out.println("Hello, " + name));
Lambdas are implementations of Functional interface...so either implicitly (by a compiler or at run-time) or explicitly (by code...assignment) they are going to be used. Practical example is
- Predicate : usage across code for filtering.
- Functions : Map.computeIfAbsent("xxx", s -> s.length());
- BiFunction : salaries.replaceAll((name, oldValue) -> name.equals("Freddy") ? oldValue : oldValue + 10000);
- Consumers : List.forEach(name -> System.out.println("Hello, " + name));
edited 32 mins ago
answered 38 mins ago
Amit
386111
386111
add a comment |
add a comment |
We've always had functional interfaces before JDK8 but no lambdas, method references etc.
As of JDK8, they provide a target type for lambda expressions, method references and in turn, have better readability and more compact code.
Example, prior to Java-8 if you wanted to provide some logic that will be executed each time a Button
component is clicked you'd do:
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
This is bulky, hard to read and not compact enough. because EventHandler
is by definition a functional interface i.e. it has a SAM
as of jdk8 you can now do:
btn.setOnAction(event -> System.out.println("Hello World!"));
You only see the part of the code you care about i.e. the logic to be executed when the button is clicked.
Further, due to the fact that we can use functional interfaces as target types for lambda expressions & methods references, this would be useful when:
- passing a comparator to a sort method e.g.
List.sort
,Stream.sorted
,Collections.sort
etc. - passing a block of code to run a task in a separate thread
etc...
while keeping the code readable, compact and concise.
Functional interfaces are used extensively in the Java-stream API.
There's no reason for you to create your own functional interface except there's not one that meets your requirements from java.util.function
or the name of the functional interface is not as readable so thus you may create your own.
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
We've always had functional interfaces before JDK8 but no lambdas, method references etc.
As of JDK8, they provide a target type for lambda expressions, method references and in turn, have better readability and more compact code.
Example, prior to Java-8 if you wanted to provide some logic that will be executed each time a Button
component is clicked you'd do:
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
This is bulky, hard to read and not compact enough. because EventHandler
is by definition a functional interface i.e. it has a SAM
as of jdk8 you can now do:
btn.setOnAction(event -> System.out.println("Hello World!"));
You only see the part of the code you care about i.e. the logic to be executed when the button is clicked.
Further, due to the fact that we can use functional interfaces as target types for lambda expressions & methods references, this would be useful when:
- passing a comparator to a sort method e.g.
List.sort
,Stream.sorted
,Collections.sort
etc. - passing a block of code to run a task in a separate thread
etc...
while keeping the code readable, compact and concise.
Functional interfaces are used extensively in the Java-stream API.
There's no reason for you to create your own functional interface except there's not one that meets your requirements from java.util.function
or the name of the functional interface is not as readable so thus you may create your own.
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
We've always had functional interfaces before JDK8 but no lambdas, method references etc.
As of JDK8, they provide a target type for lambda expressions, method references and in turn, have better readability and more compact code.
Example, prior to Java-8 if you wanted to provide some logic that will be executed each time a Button
component is clicked you'd do:
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
This is bulky, hard to read and not compact enough. because EventHandler
is by definition a functional interface i.e. it has a SAM
as of jdk8 you can now do:
btn.setOnAction(event -> System.out.println("Hello World!"));
You only see the part of the code you care about i.e. the logic to be executed when the button is clicked.
Further, due to the fact that we can use functional interfaces as target types for lambda expressions & methods references, this would be useful when:
- passing a comparator to a sort method e.g.
List.sort
,Stream.sorted
,Collections.sort
etc. - passing a block of code to run a task in a separate thread
etc...
while keeping the code readable, compact and concise.
Functional interfaces are used extensively in the Java-stream API.
There's no reason for you to create your own functional interface except there's not one that meets your requirements from java.util.function
or the name of the functional interface is not as readable so thus you may create your own.
We've always had functional interfaces before JDK8 but no lambdas, method references etc.
As of JDK8, they provide a target type for lambda expressions, method references and in turn, have better readability and more compact code.
Example, prior to Java-8 if you wanted to provide some logic that will be executed each time a Button
component is clicked you'd do:
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
This is bulky, hard to read and not compact enough. because EventHandler
is by definition a functional interface i.e. it has a SAM
as of jdk8 you can now do:
btn.setOnAction(event -> System.out.println("Hello World!"));
You only see the part of the code you care about i.e. the logic to be executed when the button is clicked.
Further, due to the fact that we can use functional interfaces as target types for lambda expressions & methods references, this would be useful when:
- passing a comparator to a sort method e.g.
List.sort
,Stream.sorted
,Collections.sort
etc. - passing a block of code to run a task in a separate thread
etc...
while keeping the code readable, compact and concise.
Functional interfaces are used extensively in the Java-stream API.
There's no reason for you to create your own functional interface except there's not one that meets your requirements from java.util.function
or the name of the functional interface is not as readable so thus you may create your own.
edited 5 mins ago
answered 39 mins ago
Aomine
39.7k73770
39.7k73770
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
add a comment |
Could you add a comment about@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not@FunctionalInterface
...
– Boris the Spider
4 mins ago
Could you add a comment about
@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not @FunctionalInterface
...– Boris the Spider
4 mins ago
Could you add a comment about
@FunctionalInterface
not being neccessary, but only being present to prevent SMIs used a lambdas from having methods added thus breaking interface compatibility. Otherwise this answer is about SMIs only - not @FunctionalInterface
...– Boris the Spider
4 mins ago
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54004144%2freal-world-example-to-use-functional-interface-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Lambda are implementations of Functional interface...so either implicitly (by a compiler or at runtime) or explicitly (by code...assignment) they are going to be used. Practical example is a Predicate usage across code for filtering.
– Amit
40 mins ago