Physics2D.Linecast what does it return?

I used this code:


also used this:

RaycastHit2D hit = Physics2D.Linecast(start,end,layerMask);

Both of them are working, how is this possible??? How can the same method return different type of object?


Physics2D.Linecast has a return type of RaycastHit2D. However if nothing is hit, it will return null.

Since null is equivalent to false and anything other return value is not equivalent to false if(Physics2D.Linecast(start, end, layermask)) works as expected.