Understanding the constructor
solidity
The solidity constructor is automatically executed when the contract is deployed. If the contract is instantiated in other contracts through new or other methods, the constructor will not be executed.
contract TestContract{
address public proxyAddress;
constructor(){
proxyAddress=msg.sender;
}
}
contract Validate{
function newContract() external returns(address){
TestContract test=new TestContract();
return address(test);
}
}
Other high-level languages
Commonly used programming languages such as java, go, python and other high-level languages will execute their constructors when instantiating objects.
Summarize
The constructor execution logic is inconsistent. Solidity only executes it once during deployment, while other languages execute it every time the object is instantiated.