So, at first I had a line saying :
Object input = .... //some come code initialising it
if(input instanceof Set<String>) {
doSomething(input);
}
However, since generic type information is erased at runtime, I cannot specify that it is a Set<String>but instead a unbounded wildcard Set<?>.
But I need to use this set for String related handling like appending to a JTextArea, so this unbounded wildcard type is not very useful when I require Strings to come out.
So, I tried this
Object input = .... //some come code initialising it
if(input instanceof Set<?>) {
doSomething((Set<String>) input);
}
This cast gets it from unbounded to a string type (I am sure it will be of Set<String> if the input is a Set) but this isn't very safe is it? I get an error saying I could suppress the unchecked cast but I feel like there may be another way of approaching this. Any ideas?
EDIT: initialised input by serialising from an input stream from a server socket on private LAN ip.