I want to make a generic method that determines whether the first parameter is null, and if it is the case returns the second which is the default, else returns the first.
Can I make this possible?
I don't know how to implement it properly.
public static <T> ifNull(Object parameter, Object default, Class<T> type) {
return type.cast(parameter == null ? default: parameter));
}
Note: this code doesn't work for real, it's just an example.