为什么静态方法Stream.empty()里面没有形参却有形参类型?

Why is there formal parameter type in static method Stream.empty() although there is no parameter in the method?

形参类型在Java 8中是允许的,一般在有带[=的参数时使用21=]通用类型 AFAIK。

不过,确实有一些方法没有参数但是形式参数类型反正。例如,

<T> Stream<T> java.util.stream.Stream.empty()

谁能解释一下?

此处需要泛型类型参数来指定 returned 空 Stream 的元素类型。否则此方法将 return 原始 Stream 类型。

例如:

Stream<String> stream = Stream.empty();