Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
June 14, 2016 How to call one static method from another? | ||||
---|---|---|---|---|
| ||||
Hi, Just can't found information about "this" for static methods. Can anyone explain how to call current class from static methods? For example I have some class and I need to call some static method of current class from another static method. I don't like to use full class name for that, but I didn't know what need to use instead of "this". I sure it must be something like "self". :( |
June 14, 2016 Re: How to call one static method from another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Konstantin Kutsevalov | May be my question was not enought clean... this is example of code: ``` class ClassName { public static void function method1() { // do something // and now I need to call other static method ClassName.method2(); // What I can use insted of full class name? // Like "self.method2()" } public static void function method2() { //... } } ``` |
June 14, 2016 Re: How to call one static method from another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Konstantin Kutsevalov | On Tuesday, 14 June 2016 at 07:20:47 UTC, Konstantin Kutsevalov wrote:
> May be my question was not enought clean...
> this is example of code:
>
> ```
> class ClassName {
>
> public static void function method1()
> {
> // do something
> // and now I need to call other static method
> ClassName.method2(); // What I can use insted of full class name?
> // Like "self.method2()"
> }
>
> public static void function method2()
> {
> //...
> }
> }
> ```
Simply:
method2();
Anyway I guess you mean public static void method1() { } without "function"
Andrea
|
June 14, 2016 Re: How to call one static method from another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Tuesday, 14 June 2016 at 07:35:36 UTC, Andrea Fontana wrote:
> On Tuesday, 14 June 2016 at 07:20:47 UTC, Konstantin Kutsevalov wrote:
>> May be my question was not enought clean...
>> this is example of code:
>>
>> ```
>> class ClassName {
>>
>> public static void function method1()
>> {
>> // do something
>> // and now I need to call other static method
>> ClassName.method2(); // What I can use insted of full class name?
>> // Like "self.method2()"
>> }
>>
>> public static void function method2()
>> {
>> //...
>> }
>> }
>> ```
>
> Simply:
> method2();
>
> Anyway I guess you mean public static void method1() { } without "function"
>
> Andrea
Yep, it's my mistake about "function" :)
Thanks!
|
June 14, 2016 Re: How to call one static method from another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Tuesday, 14 June 2016 at 07:35:36 UTC, Andrea Fontana wrote:
> Simply:
> method2();
Also, typeof(this).method2();
|
June 14, 2016 Re: How to call one static method from another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | On 6/14/16 6:08 AM, pineapple wrote:
> On Tuesday, 14 June 2016 at 07:35:36 UTC, Andrea Fontana wrote:
>> Simply:
>> method2();
>
> Also, typeof(this).method2();
>
Yes, if you want to distinguish between another function named method2.
-Steve
|
Copyright © 1999-2021 by the D Language Foundation