Skip to main content

All 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> { ...
voidnull's user avatar
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&...
marcodeono's user avatar
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<? ...
sumit's user avatar
  • 49
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 ...
MatiasG19's user avatar
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 ...
Shubbi's user avatar
  • 65
-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 ...
maddina prudhviram's user avatar
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 ...
Xore's user avatar
  • 11
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 ...
Bruce_Wayne's user avatar
  • 1,614
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 ...
lolcio's user avatar
  • 352
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....
xanmcgregor's user avatar
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 ...
Mira's user avatar
  • 73
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 ...
user7148508's user avatar
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(); ...
AleMal's user avatar
  • 2,087
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", () -&...
Display Name's user avatar
  • 1,221
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 ...
Shubham Jain's user avatar
  • 1,984

15 30 50 per page