Immutable

Solidity

परिभाषा

Immutable keyword variables को mark करने के लिए use होता है जिन्हें constructor में set किया जा सकता है लेकिन बाद में modify नहीं किया जा सकता। Immutable variables constant से ज्यादा flexible हैं (runtime values allow करते हैं) लेकिन regular state variables से cheaper हैं (bytecode में inline होते हैं)।

English version

The immutable keyword is used to mark variables that can be set in the constructor but cannot be modified later. Immutable variables are more flexible than constant (allow runtime values) but cheaper than regular state variables (inlined in bytecode).

Code Example

contract Token {
    // Constant : valeur connue à la compilation
    uint256 public constant DECIMALS = 18;

    // Immutable : valeur définie au déploiement
    address public immutable owner;
    uint256 public immutable maxSupply;

    constructor(uint256 _maxSupply) {
        owner = msg.sender;
        maxSupply = _maxSupply;
    }
}

संबंधित शब्द

Solingo पर इस concept को practice करें

Immutable को interactive exercises और integrated IDE के साथ master करें।

मुफ्त में शुरू करें