identityFunction() simply returns the function itself, to be used on different objects.
Following is a usage example:
String result = identityFunction().apply("Hello");
The type safety warning is important. It's there because IDENTITY_FUNCTION is implemented such that the compiler can't guarantee that the function returns the same type as the input.
Consider the following alternative implementation:
private static UnaryFunction<Object> CONST_FUNCTION = new UnaryFunction<Object>() {
public Object apply(Object arg) { return "Default"; }
};
This implementation always returns a string, so it's obviously not safe to return it as a unary function on a generic data type.
In our case (IDENTITY_FUNCTION), the proof that the returned type is the same as the input type is inside the implementation. We return the same instance, so it's guaranteed to have the same type. When you suppress type safety warnings, it's recommended to justify it with a proof.