Set<String>set=newHashSet<String>();Strings1="hello";Strings2="world";set.add(s1);set.add(s2);Objectobj=set;现在问题是怎么把obj转换为Set<String>类型?... Set<String> set = new HashSet<String>();
String s1 = "hello";
String s2 = "world";
set.add(s1);
set.add(s2);

Object obj=set;

现在问题是怎么把obj转换为Set<String>类型?
(Set)obj后有个警告:
Unchecked cast: 'java.lang.Object' to 'java.util.Set' less... (Ctrl+F1)
Signals places where an unchecked warning is issued by the compiler, for example:
void f(HashMap map) {
map.put("key", "value");
}

Hint: Pass -Xlint:unchecked to javac to get more details.
除了@SuppressWarnings("unchecked"),怎么才能正确消除这个警告?
本回答被网友采纳