How do I declare an array of Strings in a getter / method declaration ?
Ex ( none of these exemples works ) :
class Test
getter var1 : String[]
getter var2 : String*
getter var3 : Array(String)
end
How do I declare an array of Strings in a getter / method declaration ?
Ex ( none of these exemples works ) :
class Test
getter var1 : String[]
getter var2 : String*
getter var3 : Array(String)
end
getter var3 : Array(String)
This is the correct way to declare an instance variable as an Array of String. However, you'll need to assign a value, either in the declaration or in the constructor.
If it should be an empty Array by Default, you can use
getter var3 = Array(String).new
# or
getter var3 = [] of String
If you need the variable to allow a nil value, you can use
getter var3 : Array(String)?