Questions tagged [static-methods]

Methods that neither require an instance of the class nor can they implicitly access the data (or this, self, Me, etc.) of such an instance.

Static methods neither require an instance of the class nor can they implicitly access the data (or this, self, Me, etc.) of such an instance. A static method is distinguished in some programming languages with the static keyword placed somewhere in the method's signature. Static methods are called "static" because they are resolved statically (i.e. at compile time) based on the class they are called on; and not dynamically, as in the case with instance methods which are resolved polymorphically based on the runtime type of the object. Therefore, static methods cannot be overridden.

Source: "Method (computer programming)" article on Wikipedia

2793 questions
1
vote
2 answers

How do I call a public static void that is in a different class.

I have 2 classes, MainActivity and MainGame. If I have a public static void in MainActivity, and one in MainGame. How would I execute the one in MainGame from MainActivity? For example, I have this: Main Activity: public static void…
user2101454
  • 291
  • 1
  • 4
  • 7
1
vote
0 answers

static methods inheritance in backbone over different modules

I am using backbone.js for a web app. I have different component views which are derived from few base classes. Each of the view has few static methods for initializing and creating instances. For example: class Base extends Backbone.View …
Sundar
  • 173
  • 1
  • 6
1
vote
3 answers

Any way to apply staticmethod to all class methods?

Is there any way to apply staticmethod to all methods of a given class. I was thinking we can access methods in its metaclass (in new of metaclass) and apply staticmethod, but i am not aware of syntax. Can any one please shed light on this?
Neil
  • 459
  • 2
  • 6
  • 16
1
vote
1 answer

python: is this a good way to use the same function name for both classmethod and method?

class A(object): @classmethod def print(cls): print 'A' def __print(self): print 'B' def __init__(self): self.print = self.__print a = A() a.print() A.print() I think it's too ugly, is there any other…
lifei
  • 235
  • 2
  • 10
1
vote
3 answers

distinguishing between static and non-static methods in c++ at compile time?

For some tracing automation for identifying instances i want to call either: a non-static method of the containing object returning its identifier something else which always returns the same id My current solution is to have a base class with a…
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
1
vote
1 answer

Constexpr construction and static member is not working

Consider the following code: #include #include template class Test { public: constexpr Test(const Type val) : _value(val) {} constexpr Type get() const {return _value;} static void…
Vincent
  • 57,703
  • 61
  • 205
  • 388
1
vote
2 answers

Getting xml file inside Jar file

I'm using NetBeans and i wrote this function, with help of other thread to a same question, but i get error of line "InputStream is = getClass().getResourceAsStream(xml_file_path);" saying: "non-static method getClass() cannot be referenced from a…
Aviadjo
  • 635
  • 5
  • 17
  • 36
1
vote
2 answers

Call static method in static class from asp page

When I call static method from asp page I got this Compilation Error: CS0103: The name 'Tudo' does not exist in the current context Line 10: Tudo is a static…
oteal
  • 614
  • 2
  • 13
  • 25
1
vote
1 answer

No enclosing instance of type ContactsXmpp is accessible?

this is the class i am using public class ContactsXmpp extends SherlockFragmentActivity { private static Context ctx; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
1
vote
5 answers

Is using a static method cheaper than importing the whole class?

I have a small static method mymethod inside a relatively big (library) class com.package.pirulo. I can do one of two things: Either I import com.package.pirulo and then I just use pirulo.mymethod(...), or I can use direclty the method with…
Luis A. Florit
  • 2,169
  • 1
  • 33
  • 58
1
vote
1 answer

static Vs non static methods & members interaction

i have a WebMethod that serves an Ajax AutoComplete Extender as it's DataSource. FontnmsList_AutCpltDataSrc() so it must be static ,... unless I will implement it through another approach... such as Web Service, as i wouldn't like to use, and…
LoneXcoder
  • 2,121
  • 6
  • 38
  • 76
1
vote
1 answer

python static class with static method that uses self?

I'm doing a database insert script in pycassa. I want to set up a public static class that defines some variables that will get used a lot by other functions later on. Heres what I have... class ks_refs(): pool = ConnectionPool('TweetsKS') …
Guye Incognito
  • 2,726
  • 6
  • 38
  • 72
1
vote
2 answers

mergesort string method java

I need help with using merge sort with a string array. I've seen many examples of this with an int array but I need help using a string array. I can only use the .compareTo() method. This is my main method: public static void main(String[] args) { …
PintOverflow
  • 105
  • 2
  • 9
1
vote
2 answers

HttpServletRequest and static method thread-safety in Struts 2

Suppose I have a static method in a class like so: public static String getSomething(HttpServletRequest request) Which, in the method, calls request.getHeader("headerName") and request.getParameter("parameterName"). Also, In a Struts 2 Action , I…
jtyler
  • 1,055
  • 2
  • 15
  • 22
1
vote
1 answer

MonoTouch - how to override static UIView.layerClass

I'm trying to port AUISelectiveBordersView to MonoTouch. It's basically a subclass of CALayer and integration in UIView via Categories. "Translation" of AUISelectiveBordersLayer is easy, but integration point is a bit tricky. In obj-c it's done…
Shaddix
  • 5,901
  • 8
  • 45
  • 86
1 2 3
99
100