If you really wanted to, it’s possible to give the robot odometry (it knows where it is using the last known position and the motion of the wheels), and then you could calculate if what you are seeing is a wall or a ball.
However, that is very complicated and probably beyond the scope of this forum for people to help you. You would have to do your own research.
Your problem is very difficult to solve, so if I were you I would find a way to relax the constraints of the problem. Maybe you introduce a colour sensor, or you make something physical that can differentiate between a wall or a ball.
To try to do this via programming would be a feat indeed.