• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Generic = does not conform to bounds of method

 
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so generics are killing me here. Sorry for all of the questions, but you don't know until you ask, right? Why do I get the following error if I clearly declare myList to be an array of Strings and bound the method with String?

<T>fillArray(T...) in Ch15.ArrayList<T> cannot be applied to (Ch15.ArrayList<java.lang.String>); inferred type argument(s) Ch15.ArrayList<java.lang.String> do not conform to bounds of type variable(s) T


 
Sheriff
Posts: 22773
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
fillArray expects any number of Strings, or a single String[]. You are passing an ArrayList<String>. That does not match, now does it?

Don't you mean Because that does compile (with a warning about the cast to T[]).
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:fillArray expects any number of Strings, or a single String[]. You are passing an ArrayList<String>. That does not match, now does it?

Don't you mean Because that does compile (with a warning about the cast to T[]).



OK, so I wasn't passing it the instance variable list[] like I thought I was doing. I see that now, thank you!
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic