Class Demo1_ApplyFunction


  • public class Demo1_ApplyFunction
    extends Object
    Demos for generics.
    Author:
    Herbert Praehofer
    • Constructor Detail

      • Demo1_ApplyFunction

        public Demo1_ApplyFunction()
    • Method Detail

      • main

        public static void main​(String[] args)
      • applyFunction

        public static <A,​B> B applyFunction​(Function<? super A,​? extends B> fn,
                                                  A obj)
        Applies a function object on an object value.
        Type Parameters:
        A - the type of the value
        B - the type of the result
        Parameters:
        fn - the function to apply
        obj - the object value
        Returns:
        the result of the application
      • either

        static <A> List<A> either​(List<? extends A> first,
                                  List<? extends A> second)
        Returns the first list if not empty, otherwise the second list
        Type Parameters:
        A - the common base type of the elements of th two lists
        Parameters:
        first - the first list
        second - the second list
        Returns:
        the first list if not empty, otherwise the second list