File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot add values to unknown type

 
Kasun Wixkramanayake
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The generic type T is defined as: T extends List<? extends Number>

So, type T is a List of some unknown type (indicated by the question mark) that extends Number. You can't add a Long to such a list, because you don't know what the unknown type is. Suppose that someone uses this on a List<Double>. Ofcourse it shouldn't be possible to add a Long to a List<Double>.

If you want to be able to add a Long, then you can change the first line to this:

 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:If you want to be able to add a Long, then you can change the first line to this:



Or if you want it a bit more general:
Since then T could be any of List<Long>, List<Number> and List<Object>.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic