I looked into the code, everything is int -- the parameter passed to CountDownLatch constructor is int, the variable in Sync is int, the return type of Sync.getCount() is int. But CountDownLatch.getCount() returns a long? Wondering why.
4 Answers
I have a different idea: simple oversight.
When you turn to the source code, you will find that the implementation uses an internal class Sync. Sync has a getCount(), too - and that one returns int. In other words: the whole implementation is based on int; and only that one external getter is using long. I think there is absolutely no sense in that.

- 137,827
- 25
- 176
- 248
I don't know if you will find a sufficient answer to that question unless someone who designed that API answers, but it does say it is for "debugging and testing".
public long getCount() {...} // just for debugging and testing
-
yep...In multithread env, this value is not reliable. I ask this questing just wondering why using long... Thanks! – DeepNightTwo Sep 03 '11 at 02:43
Futureproofing?
Just because CountDownLatch(int) is the only existing constructor, that doesn't mean you couldn't add CountDownLatch(long) in Java 8, if anyone ever comes up with a use for that kind of thing.
The value is only indicative, not reliable, anyway.

- 8,240
- 3
- 28
- 33
I would guess it's because the int is being used to store an unsigned int, counting from 0 to 2**32-1. Although you can store an unsigned int in an int, when doing calculations with it, it is much easier to promote the value to a long, which can accommodate that range quite naturally.

- 46,189
- 17
- 92
- 133