代码之家  ›  专栏  ›  技术社区  ›  Albert

JAVA:通用函数X-> Y接口

  •  10
  • Albert  · 技术社区  · 15 年前

    我需要这样一个接口:

    interface Function<X,Y> {
        Y eval(X obj);
    }
    

    在Java中有这样的事情吗?或者我需要定义我自己的吗?

    5 回复  |  直到 9 年前
        1
  •  2
  •   Pang Ajmal PraveeN    9 年前

    here

    public interface Function<T,R>

    apply(Object)


    T
    R

        2
  •  13
  •   Nathan Hughes    15 年前

    Function interface

    public interface Function<F, T> {
      /**
       * Applies the function to an object of type {@code F}, resulting in an object of     type {@code T}.
       * Note that types {@code F} and {@code T} may or may not be the same.
       *
       * @param from the source object
       * @return the resulting object
       */
      T apply(@Nullable F from);
    
      /**
       * Indicates whether some other object is equal to this {@code Function}. This     method can return
       * {@code true} <i>only</i> if the specified object is also a {@code Function} and, for every
       * input object {@code o}, it returns exactly the same value. Thus, {@code
       * function1.equals(function2)} implies that either {@code function1.apply(o)} and {@code
       * function2.apply(o)} are both null, or {@code function1.apply(o).equals(function2.apply(o))}.
       *
       * <p>Note that it is always safe <i>not</i> to override {@link Object#equals}.
       */
      boolean equals(@Nullable Object obj);
     }
    
        3
  •  6
  •   Jorn    15 年前

        4
  •  2
  •   dogbane    15 年前

    Apache Commons Functor

    T evaluate(A obj);
    

    T evaluate(L left, R right); 
    
        5
  •  0
  •   Riduidel    15 年前