Global methods for a class (generic class)

Monkey Forums/Monkey Programming/Global methods for a class (generic class)

liviu(Posted 2013) [#1]
Hi,

I am new to monkey language, coming from C#. Why global methods are not supported in a class?

I would like to have a static (global ) lazy property in a generic class, how to implement that?

Thanks


dragon(Posted 2013) [#2]
function?


Goodlookinguy(Posted 2013) [#3]
I'm not entirely sure what you're asking, but I think the code below might be of some help.

[monkeycode]
Class ExampleClass<T>
Private
Global _Instance:ExampleClass
Public

Function Instance:ExampleClass<T>( value:T )
If Not _Instance Then _Instance = New ExampleClass<T>(value)
Return _Instance
End

' ------------------
Field value:T

Method New( value:T )
Self.value = value
End
End

Function Main:Int()
Local example:ExampleClass<String> = ExampleClass<String>.Instance("Hello")
Print example.value
Return 0
End
[/monkeycode]


liviu(Posted 2013) [#4]
Ok, thanks.
I think i got confused by the Method, Function keywords...