gpt4 book ai didi

java - 类有两个类型参数都有字符串和数字的上限 : Java

转载 作者:行者123 更新时间:2023-11-30 05:51:29 25 4
gpt4 key购买 nike

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/

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