static-methods

Static method,new thread performance question

Hey guys i just have two questions about two methods used in many controllers/servlets in my app: 1-what is the difference between calling a static method in a util class or a non static method (like methods dealing with dates i.e getting current time,converting between timezones), which is better ? 2-what is the difference between call...

C#: Do I need to lock a static class when accessing from separate threads?

I have a static class with a few methods that just take in a byte array, parses it, and returns a structure. I need to call these methods from many separate threads. Do I need a lock() or some kind of thread-safety within the methods? I can't get my head around it. ...

How can I refresh gridview in ASP.NET C# after Ajax call and executing static method?

I need to refresh data in GridView after I call static method (Asp.Net, C#). Is it possible to accomplish it? ...

Memory usage when converting methods to static methods

I started using Resharper and it indicated when a method could be made static. Would converting a few hundred methods to static methods increase the memory footprint over a large period of time? ...

Threading and static methods in C#

Here is a meaningless extension method as an example: public static class MyExtensions { public static int MyExtensionMethod(this MyType e) { int x = 1; x = 2; return x } } Say a thread of execution completes upto and including the line: x = 2; The processor then context switches and another t...

Do access modifiers work for static class functions?

I just came across code that had protected static class functions, as in: class C { ... protected: static int fun() { ... } }; I got curious if static class functions could have access modifiers and what would it mean? Since they are class globals and not pre-instance. Thanks, Boda Cydo. ...

AS3, Getting the class in which some method is defined.

Hello everyone, In ActionScript 3. Given some method! Is there a way to get the class that's defining my method (at runtime). Furthermore the method is static. Looked at http://www.as3commons.org/ but doesn't seem to find what I'm looking for. ...

When to use static classes and methods?

I have a general question...when should i be using static classes or static methods?.. I know the idea that static methods can be called without instantiating...and static classes should only be used for static methods?...but are there any performance concerns also with it...and when should they be preferred over instance methods and cla...

Wrapping an API to support dependency injection

Hi, I am interacting with an API that just has static functions, and cannot be opened up and changed. public class WindowsNativeGraphAPI { public static IEnumerable<IGraphData> GetGraphData(); public static bool DeleteGraphData(IGraphData data); } I would like to be able to pass the API into a function or ...

Abstract static factory method [getInstance()] in Java?

Of course, the following doesn't work in Java (no abstract static methods)... public abstract class Animal { public abstract static Animal getInstance(byte[] b); } public class Dog extends Animal { @Override public static Dog getInstance(byte[] b) { // Woof. return new Dog(...); } } public class Cat ext...

Static method for XMLLoader class... how to return XML data after Event.COMPLETE function?

I am attempting to build a generic XMLLoader class with a static LOAD method, with the intent to use it as follows... private var _data:XML = XMLLoader.LOAD("path/to/xml_file.xml"); Then I could use it in any client and go-to-town with e4x. The general problem I am having is with the URLLoader's COMPLETE event, which necessarily cal...

@StaticMethod or @ClassMethod decoration on magic methods

I am trying to decorate the magic method __getitem__ to be a classmethod on the class. Here is a sample of what I tried. I don't mind using either classmethod or staticmethod decoration, but I am not too sure how to do it. Here is what I tried: import ConfigParser class Settings(object): _env = None _config = None def __init_...

Is it possible how to use self.navigationitem property in static method in iphone?

In my application which have a lot of viewcontroller classes as well as tableviewcontroller classes in all classes i want to show navigationcontroller which have //creation of toolbar UIToolbar *tool = [UIToolbar new]; tool.frame = CGRectMake(0, 0, 320, 42); //create setting button UIButton *bttn=[[UIButton alloc]initWithFrame:CGRectMak...

ActionScript 3 - Returning/inspecting class value on declaration

Hello there, I'm wondering if is there any way to mimic the same behaviour we have for top level classes in AS3 for example: var myArray:Array = [1,2,3,4]; trace(myArray) // [1,2,3,4]; As you can see it returns the own object when tracing it. but if I create my own class that extends Array I get var queue:Queue = new Queue([1,2,3,4]...

Curious problem involving generics and static methods

I have a number of data classes, which share an abstract base class so i can work with them generically (sort of). They each have a static method called Lerp, which i use frequently along with a couple of other lines. I wanted to refactor this out into a method because of DRY,but it seems there's no way to do so. How do i get around this...

What's the correct way of retrieving my custom enumeration classes by their value?

I've created my own custom pseudo enumerations within my domain model to allow me to have some more verbose values. For example, my class is as follows: public abstract class Enumeration<X, Y> : IComparable where X : IComparable { public Enumeration(X value, Y displayName) { } public Y DisplayName { get { return _displayName; ...

Variable sharing inside static method

I have a question about the variables inside the static method. Does the variables inside the static method shares the same memory location or would the have separate memory? Let me make an example. public class XYZ { Public Static int A(int value) { int b = value; return b; } } If 3 different user calls exec...

How to force static class to implement specific methods?

I need to create a set of static classes and all of them need to implement the same methods. I want to find a way to force them so. I understand that static classes cannot derive anything other than System.Object. Should I use non-static methods for this? It could be, but none of the methods of this class will use instance properties......

Performance of Singleton Class Instance Method vs. Static Class Method in PHP?

Hi all, I'm interested in objective analysis of which is more performant; calling instance methods of a singleton class or methods of a static class. I've already seen this so I'm not looking for a discussion about the difference between the two or a discussion of which is "better." I'm only interested in relative performance between t...

Why are my static objects not being instantiated when first access to the static class is a static method on the base class?

I have the following class: public class DocketType : Enumeration<DocketType, int, string> { public static DocketType ChangeOver = new DocketType(1, "Changeover"); public static DocketType Withdrawal = new DocketType(2, "Withdrawal"); public static DocketType Installation = new DocketType(3, "Installation"); private Doc...