美文网首页
List定义 不能写入,但可

List定义 不能写入,但可

作者: zhimin_ | 来源:发表于2023-11-22 10:25 被阅读0次

    具体参考下面这个stackoverflow的答案

    How can I add to List<? extends Number> data structures?

    You can't (without unsafe casts). You can only read from them.
    
    The problem is that you don't know what exactly the list is a list of. It could be a list of any subclass of Number, so when you try to put an element into it, you don't know that the element actually fits into the list.
    
    For example the List might be a list of Bytes, so it would be an error to put a Float into it.
    

    相关文章

      网友评论

          本文标题:List定义 不能写入,但可

          本文链接:https://www.haomeiwen.com/subject/agwiwdtx.html