I think this may works fine in the normal API, because count() is an action so it directly returns a Long type. In Streaming, count() returns another stream, so it has this issue where Long is actually a parameter of the outer type and the compiler doesn't automate a cast.