English 中文(简体)
Java8号补编
原标题:BiSupplier in Java8

我看到<代码>BiConsumer,BiPredicate ,BiFunction,但BiSupplier或类似。 我尝试了以下法典,但有一个例外:

“Bi Supplementier发现的多种非消耗性抽象方法”。

@FunctionalInterface
public interface BiSupplier<T, R> {

    /**
     * Gets a first.
     *
     * @return a first
     */
    T getFirst();


    /**
     * Gets a second.
     *
     * @return a second
     */
    R getSecond();
}

Can some please help me with this.

问题回答

<条码>功能/代码”的概念(<> 序号>/代码>或<代码>Consumer)与<条码> 补充不同。

A simple explanation:

  • Function transforms 1 input to 1 output. BiFunction transforms 2 inputs. So theoretically, there can be TriFunction etc...
  • Predicate works the same as Function but the output is always boolean.
  • Consumer consumes 1 input and doesn t return anything (void). BiConsumer consumes 2 inputs. So theoretically, there can be TriConsumer etc...

现在,Supplier。 <代码>Supplier将任何(0项投入)转化为产出。 以上功能接口提供one(> 功能Predicatenone(Consumer)。

<代码>Supplier在nothing上创造了一些东西;正如你所知,不可能有一个以上的回归类型。 理论上的<代码>BiSupplier系指从两项内容中删除的“,在 Java环境下,这些内容没有意义(然而,“一无所有”:Supplier<String> Provide = () ->“Hi”;)。

您可以理解<条码> 补充与设计;T>,作为<条码>功能与设计;Vox T> (t don t work in practice, but the principle is the same). 现在,BiSupplier<T> 。 履历 投票 T>, 确实没有意义。

缩略语 简单地说就是说不了。 方法在 Java回一种单一的类型。

因此,你应该简单地建立一个具有两个价值观的阶层,并回报:

class MyValue<T, R> {
    private final T first;
    private final R second;

    // constructors, getters.
}

然后只使用<条码>补充和提炼;MyValue<T,R>>,而不是建立新的功能接口。

your code is wrong, you have annotated the interface with FunctionalInterface but it has got two abstract methods.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签