static-methods

accessing static member from non-static function in typescript

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 06:02:01
I am trying to access a static member from a non-static function in the class, and I get an error saying Static member cannot be accessed off an instance variable this is how my code looks - class myClass { public static testStatic: number = 0; public increment(): void { this.testStatic++; } } From what I understand of static members/methods, we shouldn't access non-static members in static functions, but vice-versa should be possible. the static member is already created and is valid, so why can't I access from my non-static method? Access static members from inside the class the same way you

Java method call chaining in static context

血红的双手。 提交于 2019-12-05 05:42:29
In StringBuilder class I can do like this: StringBuilder sb = new StringBuilder(); sb.append( "asd").append(34); method append returns StringBuilder instance, and I can continuosly call that. My question is it possible to do so in static method context? without class instance Yes. Like this (untested). public class Static { private final static Static INSTANCE = new Static(); public static Static doStuff(...) { ...; return INSTANCE; } public static Static doOtherStuff() { .... return INSTANCE; } } You can now have code like. Static.doStuff(...).doOtherStuff(...).doStuff(...); I would recommend

.Net Static Methods and it's effects on Concurrency?

旧时模样 提交于 2019-12-05 05:31:16
问题 I am currently building an API which will be used by a webservice. I was wondering what performance issues I could meet if I built my API using a large amount of static methods . The original idea was to build expert objects which act as services. In a single user environment this approach was great! But I will soon need to port this to a multi/concurrent user environment. What kind of performance issues might i encounter with this kind of architecture? Best regards, Edit: The static methods

Appropriate use of Static Method

陌路散爱 提交于 2019-12-05 04:55:11
Conceptually, is it appropriate to use a static method (C#) when the method will only take inputs and reformat the input as the output? For example: public static string FormatString(string inputString){ return "some formatting" + inputString + "Some other formatting"; } If I were to have a few of these types of methods, would a static "utility" class be a good idea? I'd agree with the other answers so far that it certainly makes sense a lot of the time. Sometimes , you may want to actually give yourself a little more flexibility by defining an interface and implementing that with instance

Why do static methods need to be wrapped into a class?

守給你的承諾、 提交于 2019-12-05 03:19:06
Sorry for the unlearned nature of this question. If there's a simple answer, just a link to an explanation will make me more than happy. After 6 months programming I find static classes to be somewhat useful for storing routines that apply to many different classes. Here's a simplified example of how I use static classes, it's a class for parsing text into various things public static class TextProcessor { public static string[] GetWords(string sentence) { return sentence.Split(' '); } public static int CountLetters(string sentence) { return sentence.Length; } public static int CountWords

Guice - Inject dependency into a class with static helper methods

穿精又带淫゛_ 提交于 2019-12-05 02:56:58
I'm still new to Guice and haven't used any DI frameworks before. After reading the official wiki and many other documents I'm still unable to wrap my head around it completely. In my particular case I want to write a EL taglib function that uses some other (to-be-injected) class. As all taglib functions have to be declared as static, I can't just @Inject my dependency via constructor or setter. I thought of using the requestStaticInjection() method described in http://code.google.com/p/google-guice/wiki/Injections#Static_Injections but I unable to get it to work and haven't been able to find

How can I call member variables of a class within a static method?

早过忘川 提交于 2019-12-05 01:38:44
I am using some method to autoload helper files with functions. The only problem I am having now, is how to call the variables in that class. Because I am not instantiating it as an object, $this won't work. But what will? class some_helperclass { var $some_variable = '007'; public static function some_func() { //return 'all ok'; if (self::some_variable !== FALSE) { return self::ip_adres; } } I can call the function from anywhere now with the help of spl_autoload_register() . some_helperclass:: some_func(); You have to use self::$some_variable . Put the $ in there. http://www.php.net/manual/en

Call static method from a string name in PHP

我只是一个虾纸丫 提交于 2019-12-05 01:25:51
I need to call a static method of a class, but I only have a classname, not an instance of it. I am doing it this way. $class = new "ModelName"; $items = $class::model()->findAll(); It works on my computer, but when I move to the server, it throws an unexpected T_PAAMAYIM_NEKUDOTAYIM , so I think it actually expects model to be a variable instead of a method. PS: If it helps, it's Yii framework, so if there's another way to call the find() functions, it's ok to me. Thanks in advance This is because your server runs a version of PHP earlier than 5.3.0, in which this syntax is not supported.

what is the meaning of 'static' in a method header?

℡╲_俬逩灬. 提交于 2019-12-04 23:25:30
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 7 years ago . I want to understand what does the word 'static' do in the 'writeNumbers' method header?: public class DisplayClass { /** * @param args */ public static void main(String[] args) { writeNumbers(); } public static void writeNumbers() { int count; for(count=1; count<=20; count++) { System.out.println(count); } } } 回答1: The term static means that the method is

Is an instance of a class automatically created when you first call a static method

二次信任 提交于 2019-12-04 22:47:12
I would like to know if you have a class with only static methods in it, does an actual instance of the class get created somewhere when you call 1st static method? This is somewhat confusing to understand in terms of memory management as you never actually call the constructor or create an instance of the method explicitly. If an instance does get created, I would like to better understand where this instance lives and for how long. No. Calling a static method does not require (or create) an instance of a class . See also JLS-8.4.3.2 static methods which says (in part) A method that is