第一个<E>在public static <E> Set <E> someFunction(){}中表示什么

JNL*_*JNL 0 java generics

想知道什么the first <E> in the <E> Set<E>意味着什么?

例如,在以下代码中;

我知道它是一个返回类型的公共静态方法Set<E>,但从未见过<E> Set<E>?

public static <E> Set<E> union(Set<E> s1, Set<E> s2) {
   Set<E> result = new HashSet<E>(s1);
   result.addAll(s2);
   return result;
}
Run Code Online (Sandbox Code Playgroud)

任何有关相同的帮助/参考将不胜感激.

cyo*_*yon 7

<E>表示该方法union是一个泛型方法,它具有带名称的泛型类型参数E.否则编译器会认为这E是一种类型.

参考