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.

learn more… | top users | synonyms (1)

1
vote
0answers
27 views

Access to undeclared static property

My code snippet: public static function saveEntryView($content, $conf, $m_name, $m_firstname, $m_street, $m_zipcity, $m_phone, $m_email, $m_rooms, $m_etage, $m_wohnberechtigungsschein, $m_member, $...
6
votes
2answers
97 views

What is the purpose of a static method in interface from Java 8?

Why are static methods supported from Java 8? What is the difference between the two lines in main method in below code? package sample; public class A { public static void doSomething() { ...
2
votes
1answer
46 views

es6 class pass this to a static class functions

i have this class import { ObjectUtilities } from '~/utils/'; class Object{ constructor(object) { Object.assign(this, { ...object }); } utils = ObjectUtilities; } and this ...
0
votes
0answers
16 views

Combined static/instance method or similar lazy code reuse technique possible?

Edit: another way to ask this -- Is there a workaround EITHER for a static method to access the calling instance OR for an instance method to accept a non-instance in the self parameter? Trying to do ...
0
votes
2answers
41 views

Bad sign if I need a method of a class without calling a constructor because constructor needs parameters?

class Test { private $flag; public function __construct($flag) { $this->flag = $flag; } public function a() { if ($this->flag) { $...
-5
votes
2answers
44 views

static variable inside static method in java

While declaring a variable as static inside static method is giving error(compile time error). My code is here:- public class MainStatic { public static void main(String[] args) { System....
2
votes
0answers
15 views

Typing static methods returning class instance [duplicate]

How can I type a static method that returns an instance object? import typing class foo(object): @staticmethod def getOne() -> foo: return FooRegister().get() FooRegister contains all ...
0
votes
3answers
74 views

Difference between Static function declaration and the normal function declaration in Javascript?

There are many ways one can declare a function in javascript. One of the ways is declaring a class and a static function inside is as showed below. class className { static fucntionName() { } } ...
0
votes
0answers
9 views

C# calling static method in another assembly from static constructor

I have 3 assemblies, A, X and Y. Classes in assemblies X and Y represent user-controls for being placed onto windows' areas. There is a piece of code in static constructors of classes in assemblies X ...
-1
votes
0answers
33 views

Java - How to know when to use OOD paradigms versus static methods

I've seen various forms of this question posted quite a lot, but there are still times where I am confused on whether or not I am making the best design choices, or whether or not this particular ...
-1
votes
0answers
12 views

reading in a data file and analyzing it with methods.

I would like to create a program that tracks weight lifted in a competition. I would like to read in a data file from a weightlifting competition and analyze the data using methods. The methods I ...
1
vote
2answers
51 views

python how to call static method from inside of a class body

Let's assume I have a class, with a static method, and I want a class property to be set to the value that this method returns: class A: @staticmethod def foo(): ...
1
vote
1answer
22 views

how to mock “new FileOutputStram()” written in public static method using Powermockito

Problem: I am writing a test case for a method from which a public static method with below code is called: final File file = new File(filePath); final OutputStream out = new FileOutputStream(...
5
votes
3answers
86 views

Why doesn't super() work with static methods other than __new__?

I understand that __new__ is a static method and super() can be called from it create a new object, like so: >>> class A: ... def __new__(cls): ... print('__new__ called') ... ...
1
vote
1answer
15 views

How to dynamically choose subclass from inherited class while defining global methods

This is my first real foray into Python classes, so please excuse any misuse of terms. I'm trying to use the Factory Pattern approach to choosing a subclass dynamically, based on a URL provided by ...
0
votes
3answers
51 views

Pass reference of static method to a function

I found in Swift you can store a reference of a static method without actually executing it: class StringMama { static func returnString(s:String)->String { return s } } var stored =...
2
votes
2answers
45 views

Why is class variable accessible via class instance? [duplicate]

I have created class Circle with no instance variables. I've added a class-method from_diameter to generate the circle with given diameter. class Circle: @classmethod def from_diameter(cls, ...
7
votes
2answers
70 views

Python static method is not always callable

While parsing attributes using __dict__, my @staticmethod is not callable. Python 2.7.5 (default, Aug 29 2016, 10:12:21) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type "help", "copyright", "...
1
vote
2answers
50 views

How do I access Android SharedPreferences from a static method in a class without passing in a context reference?

I have just one class where I need to access SharedPreferences: public class MyUtils { public static String packageMe(Object input){ // do stuff here // need SharedPreferences ...
0
votes
2answers
35 views

Static member function assigning value without return statement [duplicate]

In the class, we have a static member function called set_value. This function, since static allows it, can be accessed by the main() given the scope resolution by class Something. Its return type is ...
0
votes
2answers
73 views

Order of 'static' function keyword vs return type specifier in C [duplicate]

Hopefully this is not a duplicate of a number of other questions relating to the meaning of 'static' functions in C. We support some legacy native C code containing things along the following lines .....
-1
votes
0answers
146 views

Private string vs private static string in C#

I declared: private string _searchApNo; and in the Page_Load function.. if (Master.ScriptManager.IsInAsyncPostBack) { string apbseid = Master.ScriptManager.AsyncPostBackSourceElementID; ...
3
votes
1answer
60 views

Why is this static method slowly taking longer to complete?

I have a static method that I use to process ResultSets and have it give back an object. Sometimes it can get called many times over and over again. For instance, in a current project I am working on, ...
-3
votes
3answers
57 views

Static methods in Java8

Java8 allows interface to have static method. It would be really helpful if anybody explain in which scenario we might need to go for interface with static methods. Thanks in advance.
0
votes
1answer
38 views

Make classes and objects of “main-project” known to “plugin-project” in C#

I have an application and want to integrate the possibility for others to write plugins for this application. My first approach was just like this: Creating a simple plugin mechanism I also need to ...
0
votes
0answers
18 views

JavaFX setHGrow and setMargin static methods [duplicate]

since these methods are static i can either call it from an instance of HBox or directly. The question is how do i do it directly? I see examples like : instead of using : HBox hbox = new HBox(); ...
0
votes
2answers
26 views

C# How do I call a method from another class inside of my interface without making the method static?

I am trying to ping google to check to see if I am connected to the internet, and I want to implement this in one of my interfaces, but I am unsure how to do this as my method is not static. Any help ...
0
votes
1answer
33 views

Hide something in all objects of the same class

I'm trying to hide a UILabel in every object (UIView) of the same class in my app. I tried something with a static class method but I'm not able to access to the instance variable. MyView.h @...
2
votes
2answers
154 views

ASP.NET and static method in controller

Assume that WebApi2 controller has a SearchClient which is configured in scoped-lifestyle dependency on startup. public class SearchController : ApiController { private readonly SearchClient ...
0
votes
1answer
52 views

Static method is not accessible through a reference variable in java

I am just trying to see if I can access static variable through a ´static´ method using a ´reference variable´ that is initialized to ´null´ (I know this is not recommended). But I can't seem to be ...
0
votes
2answers
141 views

Equivalence of static methods in Go

Let's say in Java, I have class CryptoFormat, which has a static method named getLegacyFormat(). When I want to use the method, I just need to call CryptoFormat.getLegacyFormat(). This is clear ...
0
votes
0answers
60 views

Will Static class cause too much memory usage when frequently used in C# [duplicate]

I have a static class in C# having a static method which executes a sql query passed as parameter and returns the dataset as result. My concern is will the static method cause high memory usage when ...
0
votes
1answer
54 views

In Java where do the static methods go during the creation of an object in java?

If there is a class with some methods, whenever we create a new object then that object gets created on the heap with the fields and methods. If we have a class with static and normal methods and we ...
0
votes
1answer
36 views

Does python static method consume less memory then instance method

I have several instance methods that use self within them, but only in a couple of places. So I can pass those values directly from where I am calling these methods with a parameter and create the ...
0
votes
3answers
47 views

accessing a static dict in Python 3.6

I have an Enum class of compass directions as follows. I also have an 'opposites' dict declared in the same class. from enum import Enum class Compass(Enum): N = 'N' # North S = 'S' # ...
0
votes
2answers
115 views

only one companion object is allowed per class in Kotlin

I was switching from Java to kotlin for Android Devlopment. When I searched about equivalent of Java static methods in Kotlin, I found that companion object is. But the problem is while creating more ...
1
vote
1answer
55 views

Odd construction, java converting static method to class

I recently stumbled upon a piece of code which I couldn't explain with my understanding of java. I've created this small version of the same kind of construction: public class StaticMethodClass { ...
-1
votes
1answer
29 views

how to let a library know a non activity class?

Maybe this answer exists but I couldn't find it here nor google. I have a static singleton class named Handler (non activity class). I added a library to my project and I would like to use the ...
1
vote
1answer
16 views

How to change method implementation without changing it to be not static

For example: class a: @staticmethod def aaa(): print 'a' a.aaa() a.aaa = lambda: raise ValueError('a') a.aaa() The second time python raises an error that I didn't pass an instance ...
0
votes
1answer
20 views

Issue in Return type declarations of a static function - PHP 7.0.0

I'm facing the issue in Return type declarations of static function in PHP 7.0.0 version. Reference: http://php.net/manual/en/migration70.new-features.php Kindly look at the following code ...
-1
votes
1answer
35 views

calling the static method in main class using reflection

this program recover the 2 group of the numbers from user that it compare then if the first one is bigger pointA receive one grade if not pointB receive one grade and it continues until last number....
0
votes
0answers
32 views

Implementing java member `static {…}` in c++11/14 [duplicate]

This is a java example: public static class Decoder { private final boolean isURL; private final boolean isMIME; private Decoder(boolean isURL, boolean isMIME) { this.isURL = ...
0
votes
0answers
48 views

Typescript: Static methods unable to access private properties in constructor

Trying to make a static function give access to a property xdate, which was initialized in the constructor (in typescript 1.5.3). this.xdate is accessible in all other instance methods. it remains ...
0
votes
1answer
60 views

Ownership of static fields & methods in Java

I'd like to ask a question about classes and the "mechanism", via which Java loads them on memory, particularly regarding the creation of static fields and methods. A class may have static fields and ...
2
votes
1answer
40 views

Pytest not collecting staticmethod

I have a test class with some static methods along with normal methods. The problem is that pytest is not collecting static methods. I couldn't find anything in the documentation regarding this. How ...
2
votes
1answer
35 views

How to use Mockito properly on Static methods wrapped inside non-static methods?

so I'm trying to use Mockito on a method that has a static method in it. The reason is I cannot use PowerMock so I wrapped the method under non-static method. public class WrapperUtil { public ...
0
votes
1answer
107 views

initialize static var value from variable in Struct in Swift 3

Im learning swift 3 and I have a question here Sorry for wrong example..couldnt think of logical example enum Restaurant : String { case wendys = "wendy's" case chickfila = "chick fil'a"...
1
vote
1answer
23 views

Static Generic Methods, Type Inference causes java.lang.VerifyError: Verifier rejected class

Consider these classic Person polymorphic hierarchy... super-interface public interface Person { String getName(); interface Builder<P, B extends Builder<P, B>> { B ...
4
votes
3answers
75 views

The suitable way for avoiding static method (in Util class maybe) which use for updating UI

I'm beginner in Android, I read and see if use the static method in Util class for updating UI is not good for unit test. How do I avoid it in suitable way for maintaining code and unit test ? ...
-2
votes
2answers
44 views

PHP Error - Exception: Using $this when not in object context

Hi i'm having this error with this example code. Exception: Using $this when not in object context <?php Class A { public function test($str) { return trim($str); } } Class B { ...