I have done a lot of searching for what this compiler error <identifier> expected means, and none of them seem to apply to my situation. Really sorry if this is a duplicate or basic info, but I can’t find anything anywhere.
The following code works fine. Note that I am positive myObject1 is indeed a HashSet<String> so the cast is ok.
@SuppressWarnings("unchecked")
HashSet<String> s1 = (HashSet<String>) myObject1;
The following code does NOT work fine. It will compile, but with warnings.
@SuppressWarnings("unchecked")
HashSet<String> s1;
s1 = (HashSet<String>) myObject1;
So then I try the code below.
@SuppressWarnings("unchecked")
HashSet<String> s1;
@SuppressWarnings("unchecked")
s1 = (HashSet<String>) myObject1;
Now it refuses to even compile, giving me the <identifier> expected error that is puzzling me so much. The ^ symbol in my command line is pointing right before the = in the last line. I’m not sure what on earth I could be expected to put BETWEEN the s1 and the =.
Any ideas? Thanks!
You can’t apply an annotation to a simple assignment statement. From section 9.7 of the JLS:
I agree that the compiler error message could be rather clearer, admittedly…