这个警告在 solidity 中的含义是什么?

What's the meaning of this warning in solidity?

当我编写代码时,我在代码的第 10 行收到警告。谁能告诉我这个警告是什么意思?

我的代码

// SPDX-License-Identifier: UNLICENSED

pragma solidity >=0.5.0 < 0.9.0;

contract PracticeTest // It's a class
{
    string name ;
    uint256 age;

    constructor() public
    {
        name = "Ali";
        age = 21 ;
    }
}

这是警告

Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
  --> contracts/PracticeTest.sol:10:5:
   |
10 |     constructor() public
   |     ^ (Relevant source part starts here and spans across multiple lines).

Visibility (public / internal) is not needed for constructors anymore: To prevent a contract from being created, it can be marked abstract. This makes the visibility concept for constructors obsolete.

来源:https://docs.soliditylang.org/en/v0.8.13/070-breaking-changes.html#functions-and-events


因此,如果您使用 Solidity 0.7 或更新版本编译合约,构造函数可见性(在您的情况下 public)将被忽略,您可以安全地删除它。

constructor()
{
    name = "Ali";
    age = 21 ;
}