Now i'm confused

Heres one for you.
4 men are captured in the desert and buried up to there necks in the sand.

All facing the wall one behind the other, 3 on one side and 1 on the other.
There capture places a hat on each of there heads, 2 are black and 2 are white. He tells them "if one of you can tell me the color of your hat, you are all free to go. But if the answer is wrong, I will shoot you all"
Then men are not allowed to talk to each other and they can only see whats in front of them.
After about 10 mins, one of them says " i have a black hat on" (it could be white, doesn't matter) The answer was correct and they were all free'd.
You have to tell me which one it was.