Physics2D.Linecast what does it return?

I used this code:

if(Physics2D.Linecast(start,end,layerMask)){
//SOME 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?

Thanks.

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.