[英]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
}
那么如何讓它返回 HashSet 呢?
事實證明,你不能在 if 語句中設置 return,否則它會忽略它並仍然會要求 return 語句。 注意這僅用於返回 HashSet。 可能也適用於其他情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.