Questions tagged [functional-interface]
A functional interface in the Java language refers to an interface with a single abstract method. @FunctionalInterface is an annotation which requires a particular interface declaration to conform to this specification. The target type of a lambda expression or method reference must be a functional interface. Functional interfaces are part of the Java 8 feature set.
functional-interface
595
questions
0
votes
3
answers
118
views
Can not create Function array in Java 8
I have a class called SFunction which extends from Function in JDK 8
@FunctionalInterface
public interface SFunction<T, R> extends Function<T, R>, Serializable {
}
Now I have several ...
0
votes
1
answer
81
views
Struggling to inject my mocked Runnable into my service call
For context, I'm using Resilience4j to handle exceptions and invoke retries. This is done through RetryService.
In this function, callRunnableWithRetry() there are two params. 1st is a string, the 2nd ...
0
votes
1
answer
66
views
Java FunctionalInterface with variable number of arguments
I want to write a very lightweight library method, that will take any number of java lambda functions, execute them with auto-commit turned off. Should an error occur it would rollback. So the lambda ...
0
votes
2
answers
185
views
Predicates and functions
public static void main(String[] args) {
List<String> strings = Arrays.asList("a", "b", "c", "d");
strings.stream()
....
0
votes
1
answer
37
views
@FunctionalProtocols for Swift?
My Problem
I'm looking for a while for an equivalent of Javas @FunctionalInterface in Swift.
Swift is titled as Protocol-Oriented Programming Language and known for his Syntactic Sugar. So I hope ...
0
votes
0
answers
23
views
BiFunction error during method reference with multiple arguments
I'm working on a code to put objects to S3. I've a wrapper method that logs the call details and request/ response information. While i try to use the wrapper for s3.putObject/ s3.headObject calls, ...
1
vote
2
answers
65
views
Unable to pass Consumer<> instance
I have a class for walking a directory tree and performing an action on each file/directory. It looks like this:
class DirWalker {
public static void walkDirs(Path startingPath, Consumer<Path>...
1
vote
3
answers
97
views
Java BiFunction to manipulate data over an iteration
I'm writing a Java code that looks like this, and I have the feel it could be improved with some functional programming stuff :)
int rank = 1;
for (int i = 0; i < activities.size(); i++) {
if (...
-1
votes
1
answer
55
views
Storing methods in fields in java (cleanly)
My situation is designing my game with Javas OOP as clean as I can I need to store static methods of the another class into a field of current without using try{}catch{}. Being more specific I need to ...
1
vote
0
answers
25
views
Method compose, in interface Function
public Function<V, U> compose(Function<? super V, ? extends T> before)
Can someone explain the way "? super T" works, why we need "super" in this interface to make ...
-1
votes
1
answer
62
views
using functional interfaces in java [closed]
I have ProductSettings and ProductType. Product settings determine whether product types are enabled or not.
ProductSettings productSettings = new ProductSettings()
....
-1
votes
1
answer
74
views
How to make a static version of a Map holding getters/setters of an object?
I have a map I build when called on object that provides caller with variable names as key and getter/setter pair as values. This works as expected. My issue is that I build it every time I call for ...
0
votes
1
answer
235
views
Using lambda expression for setting values in Java
This is a question just for curiosity.
Let's say I have a Java POJO class
@Data
public class MyDto{
private String id;
}
We can set the values using setId(value), but the question is, can we use ...
1
vote
1
answer
70
views
Declaring a Function with generics to use as value in a lookup map
I'm doing something wrong but not sure what.
Trying to make a lookup map that provides me functions I can call on.
Simple demonstration of the problem:
aa.java
public class aa { /** doesn't matter for ...
2
votes
1
answer
72
views
Functional interface method calling
Why does this code return no output?
public class Test {
public static Runnable print() {
return () -> System.out.println("Hello world!!!");
}
public static void main(String[] args) { ...