java创建一个返回hashset的函数


public static HashSet<String> FunctionName(String s, int num){
HashSet<String> output = new HashSet<String>();
/*
* Code that adds elements to the hashset
*/
return output; //this doesn't return/gives me a Compilation error 
}

那么我该如何让它返回HashSet呢?

事实证明,不能在if语句中设置return,否则它会忽略它,并且仍然会要求返回语句。注意这仅用于返回HashSets。可能也适用于其他情况。

最新更新