作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 Java 中看到可以使类泛型和方法泛型。我还看到了使构造函数与类一起通用的代码。我可以只使构造函数通用吗?如果是,如何调用构造函数?
最佳答案
是的,你可以。
class Example {
public <T> Example(T t) {}
public static void main(String[] args){
// In this example the type can be inferred, so new Example("foo")
// works, but here is the syntax just to show you the general case.
Example example = new<String>Example("foo");
}
}
关于java - 我可以在不使类泛型的情况下使构造函数泛型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32531769/
我是一名优秀的程序员,十分优秀!