[SalesForce] Static method cannot be referenced from a non static context: List

I believe this is a basic query and am missing something out.
However am exasperated finding an answer to the issue and thus seek your guidance.

The intent is to create a static method generateStringArray() that can return an array. However whenever I run the code in the below form, it throws error:

Static method cannot be referenced from a non static context: List<String>

  1. My method is static and arrays can be returned from static
  2. Instead of string, if I use void and don't return, the compiler does run

Why is this throwing an error?
What part of the code is being run as a class instance and not static?
Does it have soemthing to do with the way I have defined the function or the string ?

I have checked at other solutions available for the similar issue but my query pertains to what is not static in the code?


Code

public class test_clonestring {

    public static String[] generateStringArray (Integer lenstr){    
        String[] sstring = new String[lenstr]; 

        for (Integer i = 0; i<lenstr; i++) {
            sstring[i] = 'Test ' + i;
        }            

        system.debug('STD_DBG:0:'+sstring);

        return (sstring);

    }
}

Best Answer

The code you have posted does compile. To call it you will need to use the class name like this (because the method is static):

String[] stringArray = test_clonestring.generateStringArray(5);

This will not compile:

String[] stringArray = new test_clonestring().generateStringArray(5);