def<T> method

T def<T>(
  1. T defaultValue

Returns defaultValue if an object of type T is Null or not of type T.

It may be more concise than writing default values with the ?? operator may be more concise than the default value.




T def<T>(T defaultValue) {
  if (this == null || this is! T) {
    return defaultValue;
  return this as T;