• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generics in HashSet add operation.

 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following declaration:



The add operation will not compile. I tried several forms and read HashSet, I get:
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your declaration is for a variable "s", while the error message is about code related to a variable called "set". Apparently both of these are Sets, and you seem to think that they have something to do with each other. But I suspect that the compiler considers "s" and "set" to be two different things. Perhaps you could show us the declaration for "set" instead?

More to the point, what on earth is NextObject? It looks like a class or interface name, but you seem to be using it as a variable. Of course the compiler doesn't care if you disregard standard naming conventions, but you do need to define this NextObject thing somewhere. I'm guessing that whatever it is, it's not a String, and that's why the compiler is complaining.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tool completed successfully

Got it, working too fast. Short utility coded from lamer implementation on a security site used a line number reader to construct a port number, string pair and I had coded the HashSet as being Strings, changed it to the type that is actually being added in the HashSet.add(Object) and the compiler reported as above.
 
reply
    Bookmark Topic Watch Topic
  • New Topic