简体   繁体   English

这两个构造函数有什么区别?

[英]What is the difference between the two constructors?

What is the difference between the constructors?构造函数之间有什么区别?

    class UserRepository {
    final FirebaseAuth _firebaseAuth;
    final GoogleSignIn _googleSignIn;

    UserRepository({FirebaseAuth firebaseAuth, GoogleSignIn googleSignin})
  : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance,
    _googleSignIn = googleSignin ?? GoogleSignIn();
    }

VERSUS相对

class UserRepository {
final FirebaseAuth _firebaseAuth;
final GoogleSignIn _googleSignIn;

UserRepository({this._firebaseAuth, this._googleSignin});

Briefly, on the above function, the default values are assigned when the constructor parameter are null.简单来说,在上面的 function 上,当构造函数参数为 null 时,分配了默认值。 So It always has default value.所以它总是有默认值。 (The?? operator). (运营商)。 While the below one is not.而下面的不是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM