gpt4 book ai didi

java - 如何在 API 调用中使用多个通配符

转载 作者:太空宇宙 更新时间:2023-11-04 14:40:20 24 4
gpt4 key购买 nike

我正在使用 Anthill(UrbanCode/IBM 产品),其中一个方法需要 java.lang.Class<? extends SourceConfig<?>> sourceConfigType 类型的参数。

阅读 tutorial on generics 后我发现有一个类GitSourceConfigSourceConfig 的子类但我不明白 SourceConfig<?> 的通用性如何在这种背景下工作。有任何想法吗?

最终目标是获得 GitSourceConfig对象并调用 getRepositoryUrl/setRepositoryUrl方法。 Anthill Pro API 是 here我正在看 SourceConfig类。

最佳答案

通用bounded wildcard输入您的示例 java.lang.Class<? extends SourceConfig<?>> sourceConfigType指定 sourceConfigType是可以由 SourceConfig上限类型绑定(bind)的任何类.

从教程中,

List<? extends Shape> is an example of a bounded wildcard. The ? stands for an unknown type, just like the wildcards we saw earlier. However, in this case, we know that this unknown type is in fact a subtype of Shape. (Note: It could be Shape itself, or some subclass; it need not literally extend Shape.)

注意 SourceConfig本身也是通用的,这里使用的是常规的无界通配符。

关于java - 如何在 API 调用中使用多个通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25020765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com