Write the header for a generic class named MyType. The class should have two type parameters. The first type parameter’s upper bound should be the Number class. The second type parameter’s upper bound should be the String class.
这样看起来对吗?
public class MyType<T extends Number> {}
我将如何获得第二个类型参数作为上限?我可以做 extends Number extends String 吗?
最佳答案
你这样声明
public class TestThis <T extends Number, X extends String> {}
你 x extends String 有效,请记住 String 是最终类,你不能扩展它。 Eclipse 给了我这个警告:
类型参数 X 不应受最终类型 String 的限制。 Final 类型无法进一步扩展
关于java - 类有两个类型参数都有字符串和数字的上限 : Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12649240/