【发布时间】:2021-06-23 06:53:45
【问题描述】:
我正在尝试实现 Tomcat-9 的源代码。
我有一行代码如下:
Collection<Certificate> chain = new ArrayList<>(certificateFile.getCertificates());
if (certificate.getCertificateChainFile() != null) {
PEMFile certificateChainFile = new PEMFile(certificate.getCertificateChainFile());
chain.addAll(certificateChainFile.getCertificates());
}
代码在 Eclipse 中编译得很好,但是当我尝试使用 ant builder 通过 build.xml 构建它时。我收到一条错误消息:
类型不匹配:无法从 ArrayList 转换为 Collection
为什么会观察到这种行为?有什么想法吗?
【问题讨论】:
-
有很多类叫做
Collection。你用import java.util.Collection;吗?其他类型同上:您使用的是哪个Certficate? -
为什么不用
List而不是Collection,List接口扩展了Collection。所以无论如何你都会没事的。例如List<Certificate> -
抱歉,我没有意识到您指的是this code。 “实施” 是什么意思?如果您将这些行复制到自己的文件中,则可能使用了错误的导入语句。
-
实施我的意思是我获取他们的源代码并实施我自己的 mwthods 来获取密码和协议等
-
虽然错误信息被破坏了,但这是容器协方差的 YA 案例;参见例如stackoverflow.com/questions/5082044/… stackoverflow.com/questions/3246137/… stackoverflow.com/questions/2745265/… 等等。
标签: java tomcat9 java-security