But this does not exactly answer my question. I had already solved the problem with putting extra parenthesis,
But what I am looking for is what exactly causes the problem and why the type casting doesn't work in here.
If I know the answer to this then next time I will not spend huge time to find out where the type casting has gone wrong.