简体   繁体   中英

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?

Turns out, you cannot set a return inside an if statement, otherwise it ignores it and will still ask for a return statement. Note This is only for returning HashSets. Possibly for other cases too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM