functional-interface Questions

9

Solved

As a non-Java programmer learning Java, I am reading about Supplier and Consumer interfaces at the moment. And I can't wrap my head around their usage and meaning. When and why you would use these ...
Faruq asked 9/2, 2015 at 19:0

12

Solved

I came across a new term in Java 8: "functional interface". I could only find one use of it while working with lambda expressions. Java 8 provides some built-in functional interfaces and ...
Jurisprudent asked 27/4, 2016 at 6:21

3

Solved

The purpose is to create a new Predicate usable in a stream filter : myCollectionOfElement .stream() .filter( MyStaticHelperClass.compose(MyStaticHelperClass.getSubElement1OfTheElement(),MyStatic...
Heading asked 14/4, 2017 at 16:2

3

Solved

I'm learning about Method References from Java 8 and I have difficulties understanding why does this work? class Holder { private String holded; public Holder(String holded) { this.holded = ho...
Hallux asked 16/5, 2018 at 18:28

6

Solved

I can use retrolambda to enable lambdas with Android API level <24. So this works myButton.setOnClickListener(view -> Timber.d("Lambdas work!")); This also works Runnable runLater = () -&...
Mayolamayon asked 27/7, 2016 at 8:0

9

Solved

Recently I started exploring Java 8 and I can't quite understand the concept of "functional interface" that is essential to Java's implementation of lambda expressions. There is a pretty comprehens...
Colpotomy asked 1/2, 2013 at 22:12

3

First of all, sorry for the bad title, but I find it somewhat difficult to summarize my issue in one short sentence... There's some code in our software which I'm quite unhappy with. It goes like t...
Nereid asked 21/9, 2021 at 20:4

4

Solved

The Callable and Supplier functional interfaces in java.util.concurrent and java.util.function packages respectively have the following signature- public interface Callable<V> { V call() th...
Seibert asked 7/9, 2018 at 5:38

6

Solved

Why does the below code return Predicate<String> and not boolean? My understanding is that the !s.isEmpty() check here is going against the Predicate boolean test(T t); The return type here...
Sandpit asked 5/12, 2018 at 13:8

1

Solved

I would like to get some help to understand a Kotlin code snippet about functional interface used in Http4k org.http4k.core package typealias HttpHandler = (Request) -> Response fun interface F...
Scirrhus asked 6/8, 2021 at 6:32

4

As we know in Java 8, the concept of functional interfaces are introduced. A Functional Interface has one abstract method and several default or static methods are possible. But why should a Func...
Monicamonie asked 28/4, 2014 at 13:31

3

Solved

How can a Runnable be converted to a Supplier? public <T> T useSupplier(Supplier<T> supplier) { // Does something with supplier and returns supplied value ... return value; } publi...
Khotan asked 10/2, 2019 at 15:39

4

Solved

If we have Interface with only one abstract method in it, it is by default Functional Interface. Can anyone please explain what additional advantage @FunctionalInterface annotation brings? I know t...
Scandian asked 16/6, 2018 at 22:0

6

Solved

I want to implement a functional kotlin interface (interface with a single abstract method) as a kotlin lambda. How to do that? Kotlin interface @FunctionalInterface interface Foo{ fun bar(input...
Gravelly asked 5/11, 2019 at 14:36

7

Solved

I think this question is already somewhere out there, but I wasn't able to find it. I don't understand, why it's necessary to have a functional interface to work with lambdas. Consider the followi...
Sociable asked 8/10, 2015 at 8:34

3

Solved

Suppose I have an interface: public interface Function { double function (double input); } Now, suppose I have created an instance of this interface somewhere in my main class, Function f = (x...
Akmolinsk asked 20/4, 2018 at 18:7

2

Solved

Given the following code, can someone please explain why the assertion returns true? Despite having searched around countlessly, I haven't been able to get any appropriate answer for why this might...
Poaceous asked 22/7, 2020 at 13:20

4

Solved

I'm a little confused why this doesn't work. I'm having a simple Iterable of String that I want to sort via toSortedSet() my own way. I wanted to pass a lambda to it like this: myStringIterable.toS...
Toler asked 23/8, 2018 at 8:1

8

Solved

Why do suppliers only support no-arg constructors? If the default constructor is present, I can do this: create(Foo::new) But if the only constructor takes a String, I have to do this: create(...

6

So I am trying to refactor the following code: /** * Returns the duration from the config file. * * @return The duration. */ private Duration durationFromConfig() { try { return durationFro...
Mathis asked 27/3, 2014 at 12:40

2

I have this code, which works: new JdbcTemplate(new SingleConnectionDataSource(c, true)) .query("select id, name from PLAYERS", (rs, rowNum) -> new Player(rs.getString("id&quot...
Lebkuchen asked 11/2, 2020 at 9:45

1

Solved

This feature will be coming Kotlin 1.4. Here is an excerpt from KotlinConf'19. fun interface Action { fun run() } fun runAction(a: Action) = a.run() runAction{ println("Hello") } It looks ni...
Edmundoedmunds asked 22/12, 2019 at 7:34

4

Solved

public interface MyFunc<T> { boolean func(T v1, T v2); } public class HighTemp { private int hTemp; HighTemp(){ } public HighTemp(int ht) { this.hTemp = ht; } boolean sameTe...
Fount asked 29/8, 2015 at 7:46

5

Solved

I'm trying to see if there is any way to get a list of all the interfaces in Java 8 that are functional interfaces. I'm not talking about the list on this page: https://docs.oracle.com/javase/8/do...
Jugate asked 22/3, 2017 at 3:43

1

Solved

I have two factory-methods which produce "consumers" use different approaches 👉🏻 lambda and method references: @SuppressWarnings("Convert2MethodRef") public Consumer<String...
Rifling asked 18/11, 2019 at 17:42

© 2022 - 2024 — McMap. All rights reserved.