my dog learned polymorphism
The moose likes Beginning Java and the fly likes Generics in HashSet add operation. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Generics in HashSet add operation." Watch "Generics in HashSet add operation." New topic
Author

Generics in HashSet add operation.

Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
I have the following declaration:



The add operation will not compile. I tried several forms and read HashSet, I get:
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
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.


"I'm not back." - Bill Harding, Twister
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Generics in HashSet add operation.
 
Similar Threads
How can I initialize a Set on creation?
Big performance hog with (Collection).removeAll ?
Set of Set with generics
Generic doubt
TreeSet and HashSet