All Questions
21 questions
0
votes
1
answer
45
views
Implement generic method with extended type
The basic idea is that I have an interface that transforms data into different data, and I want to use this interface to transform a specific subset of data.
public static interface Data<D> {
...
2
votes
1
answer
223
views
How to implement a Java equivalent of Rust's From trait?
Rust has a convenient method to facilitate conversion between different types: the trait From (and Into) which defines an "interface" to convert an element to an other.
pub trait From<T&...
2
votes
1
answer
91
views
Trying to mimic java functional interface
I am trying to mimic the java's Function<T,R> by writing below code :
interface SFunction<T, G> {
G apply(T t);
default <Q> SFunction<T, Q> andThen(SFunction<? ...
1
vote
1
answer
161
views
What does the Function.apply-Method do in a custom interface, when it's not overwritten?
I have trouble understanding the use of the "apply" method in the following example code. What is the apply method doing exactly, since it's not overwritten?
It's obviously returning the ...
1
vote
2
answers
1k
views
Why the functional interface is not implemented by the class?
I saw the following code in a tutorial. My question is why the interface Drawable is not implemented by the class LambdaExpressionExample2? I am familiar with composition between classes. Is that the ...
-1
votes
1
answer
654
views
Can we use lambda expression inside an interface as a default or static implementation inside interfaces? [closed]
I have this strange doubt now, As far as I know, in order to use lambda expressions it should be a functional interface having single abstract method. Now the question is can we provide its ...
0
votes
2
answers
646
views
(Java) Use functional (predicate-like) interface that outputs boolean value from Binary Tree
I'm in a bit of a trouble:
I built a Binary Tree class with some functions in it which are not interesting for the purpose of this task. Every node stores a Left and Right Child plus a Parent. Every ...
5
votes
3
answers
1k
views
Assigning object to interface variable without implementing interface
I was just learning about method refernce concept of java 8.What I found strange is the example where a method reference is assigned to the interface variable without implementing the interface, And ...
3
votes
2
answers
303
views
Java strange class cast exception
Could anyone help me understand why in 1 situation I do not have ClassCastException? At least String::trim is not a MagicFunction.
public class Main {
@FunctionalInterface
interface ...
0
votes
1
answer
89
views
Java Lambdas: Sending method name as parameter
I've run into a problem in which my class contains several methods with a lot of duplicated code. The reason behind this is that each method traverses a list of entries and calls specific entry method....
0
votes
1
answer
991
views
How to use CompletableFuture and functional interfaces of java8?
I would like to replace the class CompteBancaire to a functional interfaces, can anyone show me how to do that?
Below is the code snippet, I want to use CompletableFuture in verserArgent and ...
0
votes
1
answer
156
views
Java Reusing interface methods
This is the interface I'm using:
interface Command {
void run(int a, int b, int c);
void run(int a, int b, int c, int d, int e);
}
void add(Command c){
}
this is execution: (using the first ...
0
votes
1
answer
107
views
Java Supplier can optimize object instantiation process?
I have to develop a simple code like this:
public class TestSupplier {
public static void main(String[] args) {
// TODO Auto-generated method stub
TestSupplier ts1 = new TestSupplier();
...
3
votes
2
answers
860
views
Java: not-void methods as map values
I have some code like this:
public class A {
private final Map<String, Runnable> map = new HashMap<>();
public A() {
map.put("a", () -> a());
map.put("b", () -&...
2
votes
1
answer
984
views
How do I implement two abstract methods in Java using lambdas?
I have a Functional Interface in the code below which has one abstract method and one object method override. So when I write Lambda expression for that , how can I implement my equals method.
import ...