Java:一般功能X-> Y接口 [英] Java: general function X->Y interface
问题描述
interface函数< X,Y> {
Y eval(X obj);
}
Java中是否存在类似这样的内容,或者是否需要定义我自己的?
像这样的内置接口,尽管它只与Java 8兼容。您可以在此处找到它。
来自Javadocs:
public interface Function< ; T,R>
表示接受一个参数并产生结果的函数。 b
这是一个功能接口,其功能方法为
apply(Object)
。
类型参数:
T
- 函数输入的类型
R
- 函数结果的类型
I need an interface like:
interface Function<X,Y> {
Y eval(X obj);
}
Is there something like this in Java already or do I need to define my own?
There is a built-in interface like this, although it's only compatible with Java 8 onwards. You can find it here.
From the Javadocs:
public interface Function<T,R>
Represents a function that accepts one argument and produces a result.
This is a functional interface whose functional method is
apply(Object)
.Type Parameters:
T
- the type of the input to the function
R
- the type of the result of the function
这篇关于Java:一般功能X-> Y接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!