final String? a = null;
DDLog(a.runtimeType); // Null
DDLog(a.or(() => "456")); // 456
DDLog(a.or((){
return "111";
})); // 111
extension GetDynamicExt<T> on T {
/// 返回可选值或者 `else` 闭包返回的值
/// 例如. nullable.or(else: {
/// ... code
/// })
T or(T Function() block) {
return this ?? block();
}
}
网友评论