美文网首页
Dart - Prevent Instantiation of

Dart - Prevent Instantiation of

作者: Crazy2015 | 来源:发表于2021-05-01 22:50 被阅读0次

if you have a Dart class that only contains static methods and constants , most likey you want to make the class to be non-instantiable. However, even if you don't provide any constructor,
Dart creates an empty constructor for the class by default.

Create Private Constructor to Prevent Instantiation

The solution is creating a private constructor. By declaring a private constructor, Flutter no longer creates the defaut constructor. To make the contructor private ,
you need to user _(underscore) which means private

相关文章