Is there a way I can use the magic of generics to write a function that returns an optional if the input is optional, otherwise both non-null?
For example, I have two functions that I want to combine into one.
<code>static Timestamp dateToTimestamp(DateTime dateTime) {
return Timestamp.fromDate(dateTime);
}
</code>
<code>static Timestamp dateToTimestamp(DateTime dateTime) {
return Timestamp.fromDate(dateTime);
}
</code>
static Timestamp dateToTimestamp(DateTime dateTime) {
return Timestamp.fromDate(dateTime);
}
<code>static Timestamp? dateToTimestampOptional(DateTime? dateTime) {
return (dateTime == null) ? null : Timestamp.fromDate(dateTime);
}
</code>
<code>static Timestamp? dateToTimestampOptional(DateTime? dateTime) {
return (dateTime == null) ? null : Timestamp.fromDate(dateTime);
}
</code>
static Timestamp? dateToTimestampOptional(DateTime? dateTime) {
return (dateTime == null) ? null : Timestamp.fromDate(dateTime);
}