1

I get Test1 from Test2.map, before I use Test1 function, how can I check null of Test1?

Code:

contract Test1 {
    function someFunc() public {}
}

contract Test2 {
    mapping(uint => Test1) map;
}

1 Answer 1

2

Im Solidity, the values of mappings are 0 at default. So, of you want to find out whether an entry hasn't been set yet, try this:

if(map[key]!=address(0)){
    map[key].someFunc()
} else {
    // it's not set! 
} 
2
  • btw, the " ! " after " if( " is a mistake?
    – Shane
    Aug 9, 2018 at 7:50
  • Correct, i'll change that :)
    – Henk
    Aug 9, 2018 at 7:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.