Global methods for a class (generic class)
Monkey Forums/Monkey Programming/Global methods for a class (generic class)
| ||
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 |
| ||
function? |
| ||
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] |
| ||
Ok, thanks. I think i got confused by the Method, Function keywords... |