[英]java create a function that returns a 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
}
So how do I make it return the HashSet?那么如何让它返回 HashSet 呢?
Turns out, you cannot set a return inside an if statement, otherwise it ignores it and will still ask for a return statement.事实证明,你不能在 if 语句中设置 return,否则它会忽略它并仍然会要求 return 语句。 Note This is only for returning HashSets.
注意这仅用于返回 HashSet。 Possibly for other cases too.
可能也适用于其他情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.