static-methods

HttpContext.Current.Response inside a static method

I have the following static method inside a static class. My question is it safe to use HttpContext.Current.Response inside a static method? I want to be 100% sure that it is thread safe and is only associated with the calling thread.. Does anybody know the answer? public static void SetCookie(string cookieName, string cookieVal, Syste...

php call member variables off a class within static method

Hello, 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() { //ret...

What is so great about extension methods?

Possible Duplicate: What Advantages of Extension Methods have you found? All right, first of all, I realize this sounds controversial, but I don't mean to be confrontational. I am asking a serious question out of genuine curiosity (or maybe puzzlement is a better word). Why were extension methods ever introduced to .NET? What b...

Java static reflection on subclasses

Hi all. I am implementing a sort of ORM in Java. I am trying to do a static find method that is only in the parent class. Let me get to the point: public class DB { public static Object find (int id) { // i want to return anew instance of the calling subclass } } public class Item extends DB { // nothing here } public class ...

xajax - bad response when calling a static method

When using XAJAX I have a call to a function that trims a string. this is a simple function and works just as expected. Now I want to make this function available to the whole system so I have added it to a helper class as a static method. ever since I moved this function to this class I get a bad response, something like this. Erro...

What on earth would compell C++ to call this function?

I'm working on a programming language that uses C++ as it's target language for now. I'm hitting an exceptionally strange backtrace. #1 0x08048d09 in factorial (n=0x8052160) at ir.cpp:35 35 shore::builtin__int * __return = NULL; (gdb) bt #0 shore::builtin__int::__mul__ (this=0x8052160, other=0x8052288) at /home/alex/projects/sho...

java static vs non-static using this and event handlers

Hello, I'm trying to learn about java's event handlers and keep getting errors with type type (static/non-static) methods I create. Some code I'm trying to write looks like: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Main extends JFrame implements ActionListener{ static priva...

Java no name static method

What is this? public class ABC { public ABC() { System.out.println("world"); } static { System.out.println("hello"); } } Will print: hello world I don't really understand this, or what kind of method that static code is. ...

Should I create a separate class for this?

My project contains a lot of classes, a bunch of which can be described by XML files. Don't worry, it's not the logic or implementation in XML. It's a game, and an example would be that a game tile can be defined in XML, the image file, animation frames, etc. I'm going to end up having a bunch of functions that look like this: public ...

C++/CLI : How to declare template array as method parameters

I am a newbie to C++/CLI. What is the equivalent of the following C# code in managed C++/CLI for both the header and source file? public static bool ArrayEquals<T>(T[] a, T[] b) { return true; } ...

Python static methods - how to call a method from another method

When I have regular methods for calling another method in a class I have to do this class test: def __init__(self): pass def dosomething(self): print "do something" self.dosomethingelse() def dosomethingelse(self): print "do something else" but when I have static methods I can't write self....

Calling descendant virtual methods from static method

First let's establish this. I have public abstract class Foo { public static void StaticMethod() { } } public class Bar : Foo { } is it valid to call Bar.StaticMethod(); ??? If so, let's expand previous example: public abstract class Foo { public static void StaticMethod() { } public abstract void VirtualMethod(); ...

Are static methods in ASP.NET code-behind classes non-thread-safe?

Can I use static methods in my ASP.NET Pages and UserControls classes if they don't use any instance members? I.e.: protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { gridStatement.DataSource = CreateDataSource(); gridStatement.PageIndex = e.NewPageIndex; gridStatement.DataBind(); } private ...

Pickling a staticmethod in Python

Hello all, I've been trying to pickle an object which contains references to static class methods. Pickle fails (for example on module.MyClass.foo) stating it cannot be pickled, as module.foo does not exist. I have come up with the following solution, using a wrapper object to locate the function upon invocation, saving the container cla...

System.out.println - Is this method chaining in Java?

I am wondering about the the following piece of Java code: "System.out.println". I am right about this: "System" is a static class. ".out" is a method of class "System". This is the bit I am slighty confused about ".println"-- what class / object is this a method of? Also, is this concept known as "method chaining"? Thanks GF ...

does static methods need to use static properties ??

I am using as3. Just a simple question. If I created a static method. say I decide to call on other methods within that static method. Do those methods I call on need to be static as well? what If I used some of the properties. Not to store data permanently, but just within that process. Do those properties need to be static ?? ...

Design Perspective: Static Methods vs. Classes

Although this is a fairly common problem, I am struggling with what the best way to approach it (if it needs approached at all in this case). I have inherited a website (ASP.NET, C#) part of which contains a class full of static methods (it's a very large class, honestly). One method in particular is for sending e-mails. It has every ...

Gaining access from a static method

My brain is not working this morning. I need some help accessing some members from a static method. Here is a sample code, how can I modify this so that TestMethod() has access to testInt public class TestPage { protected int testInt { get; set; } protected void BuildSomething { // Can access here } [Script...

java generics and SuppressWarnings

I have classes abstract class A { //.... } class B extends A { //.... } class C extends A { //.... } Then I have interface Maker<T extends A> { SomeClass make(T obj); } implementations for Maker class class MakerForB implements Maker<B> { /*... */ } class MakerForC implements Maker<C> { /*... */ } and class F...

When should I use static methods in a class and what are the benefits?

I have concept of static variables but what are the benefits of static methods in a class. I have worked on some projects but I did not make a method static. Whenever I need to call a method of a class, I create an object of that class and call the desired method. Q: Static variable in a method holds it's value even when method is exec...