Reputation: 1277
private static final Set sessions = Collections.synchronizedSet(new HashSet());
I am storing sessions in a Set type reference variable called sessions
s shown above.
Now, I want to iterate over these:
for(Session s : sessions){}
However, I get a Type Mismatch error at it that says
Can not convert from element type Object to Session
How do I fix this ?
Upvotes: 0
Views: 124
Reputation: 61158
You are using a raw Set
, this means that the compiler can only know that your Set
contains Object
.
You need to specify the generic type of your collection:
Set<Session> sessions = Collections.synchronizedSet(new HashSet<>());
For more information, read this.
Upvotes: 3