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.

Filter by
Sorted by
Tagged with
-4 votes
2 answers
99 views

Why would I ever use a non-static method in Python?

So I have recently discovered why static methods in python are so useful. While writing some code, and going over some existing ones, I couldn't help but change many (or all actually) of the functions ...
killerbee88's user avatar
0 votes
1 answer
53 views

How to get data from a static event-handler for serial port

I'm currently write a method that read data consecutively from serial port in C# winform for .NET framework. I write an event handler for it, but since its static, i cannot call variable from outside. ...
zyp8x's user avatar
  • 13
1 vote
1 answer
22 views

I can invoke static methods in EL, is this as per the spec?

I am confused about the answer of this question regarding static method calls in JSF EL. I have this class with a public static method in a @Named bean: @Named public class StaticMethods { private ...
raho's user avatar
  • 141
0 votes
1 answer
45 views

Why does my function know a value of an attribute without a assignment rule? [closed]

I've started learning Python recently and got this code here: import math class Circle: def __init__(self, radius): self.radius = radius def area(self): return math.pi * self....
Lars Sk 's user avatar
0 votes
1 answer
49 views

How can I inherit a magic static singleton?

I would like to inherit from a magic static singleton in a derived: #include <iostream> int main(); class SingletonBase{ protected: int i=0; SingletonBase(int){} // friend int ...
GRamon's user avatar
  • 77
-1 votes
1 answer
17 views

Inject value from application.properies into one static value and use that value in same class static method

Just like stated in title, is it possible to implement such functionality in java? Thanks. Suppose I have a class myClass.java, is it possible to achieve below functionality public class myClass { @...
lalala's user avatar
  • 1
0 votes
0 answers
47 views

issue with class methods / async?

Using Zustand in my React project, I am defining the global authentication states as you see in the code snippet. I am also defining an Auth API to run the auth methods. However, for some strange ...
Aslan's user avatar
  • 85
-1 votes
1 answer
80 views

Who will be the method invoker of a Class with no object?

In object-oriented programming, an "invoker" refers to an object or code that initiates/invokes the execution of a method or function on another object. But my question is what if a class ...
Swapnil Mishra's user avatar
0 votes
0 answers
23 views

Why it's bad that overload a class static method with different arguments [duplicate]

I have Python codes: class A(object): @staticmethod def print(): print('A') class B(A): @staticmethod def print(val): print('B' + str(val)) And I want to use them ...
Rocky.L's user avatar
  • 59
0 votes
0 answers
20 views

In python class, how to pass returned value of a method of a class as input to another method of the same class

I am using boto3 library to establish connection to an s3 compatible storage. I had created a class with constructor that take cluster details, access key & IDs as inputs, having these initiated. ...
vpothurajula's user avatar
-2 votes
1 answer
69 views

how to create static member function from class template typedef argument?

I'm trying to build a class template where one static methodneeds to have the typedef specified in the template argument. The goal is to specify a typedef like this typedef foobar = void __stdcall foo(...
Jon's user avatar
  • 1
1 vote
0 answers
85 views

Why constructor of a statically created object is not executed before main function if the object is defined in library?

I am trying to create "plugin" factory. When an user requests creation of an object factory queries it's child factories and picks suitable one to create the object. Instances of child ...
KajzerSoze's user avatar
1 vote
0 answers
43 views

What is the cost of static and instance methods? [duplicate]

I'm planning to switch access of instantiated objects methods to static methods, but I'm not sure how to benchmark it properly and if the impact would be worse than it already is (in my opinion, you'...
Arthur Brenno's user avatar
-2 votes
2 answers
84 views

How open WPF Window in static c# Window and read from Textbox

I want to call a WPF window via Code Behind and display it in my application, no matter where I am in the application. What I am failing at is that the static method that calls the window is not ...
Kojote's user avatar
  • 7
1 vote
2 answers
65 views

OOP - Is there a name for the design pattern of using class properties or lambdas to wrap static methods (of the same name)?

I'm working with a C# class at the moment that exposes some lambda [instance] methods which serve as wrappers for static methods of the same name. Here is an example snippet: public class UserUI : ...
Austin C's user avatar
0 votes
1 answer
49 views

Is it possible to run a static method using getType function in C#? [duplicate]

I have a base class and some derived classes that have some static methods. Is it possible to run static method if I know only the object of base class. Ive tried typeof and getType methods to do it ...
a11ex's user avatar
  • 45
-2 votes
1 answer
63 views

Can I call a static method from outside a class without initializing the class?

class BaseIndicesLinker: def __init__( self, date: int) @staticmethod def some_static_function(i: int): return datetime.datetime(...) def ...
jikf's user avatar
  • 33
1 vote
0 answers
92 views

Compiler optimization of static function calls in C++ [closed]

There is some function that accesses resources over a static call and loses sometimes the pointer to it. Resource* ptr = Application::getResource("name"); That's why I made another static ...
Nick's user avatar
  • 11
2 votes
2 answers
73 views

Updating a static field by passing it as a method argument

My app will involve a lot of modifying of static fields. I'm wondering how to update the static fields from different classes by passing them as a method argument to a utility setter method. internal ...
user999666's user avatar
0 votes
1 answer
115 views

Mockito mock static method of class, but other instance methods of same class should not be mocked instead it must be called normally

I have class let say ABC. In this class there is static method public static void staticOne(){...} In same class there are non-static methods also present let say method1() method2(). In mockito I ...
Ujef Malek's user avatar
0 votes
1 answer
54 views

mock a static method in jasmine using the useClass statement

I think I probably should use a spyObject and I am on the wrong track but is it possible to mock a static function with useClass in Jasmine Angular testing? The code I am testing is: this....
Marc W's user avatar
  • 91
2 votes
1 answer
104 views

matlab Static methods are unnecessary, right?

I researched static methods and feel that static methods are non-essential in matlab.There would be no inconvenience if matlab did not provide a static method.I wonder if my above opinion is correct? ...
bokabokaboka's user avatar
0 votes
0 answers
46 views

How to add static constructor to a generic internal class in Groovy

The following code is not working because the constructor does not exist: Constructor 'Result' in 'Result' cannot be applied to '(T, java.lang.Boolean)' class External { class Result<T> { ...
Gabriel Carrera's user avatar
0 votes
0 answers
33 views

Is it bad practice to have an overloaded method with a static and non-static version of the same method?

I am working on a CRUD application in Java currently. I have classes that correlate with each table in my database. Is it bad practice to have the same method with both static and non-static versions ...
Noah Webster's user avatar
1 vote
1 answer
40 views

How to call parent static method using child class in kotlin?

I have a java class AAA with a static method: public class AAA { public static void foo() {} } and a kotlin class which extends it: class BBB : AAA() {} Now in other kotlin file I would like to ...
LLL's user avatar
  • 1,807
0 votes
2 answers
183 views

I Want to Understand How abstract class Application's launch() method work in JavaFX

in javaFX Application is an abstract class. In this abstract class there have some abstract methods which are overridden in main class which extends abstract Application class and also have static ...
Nahid's user avatar
  • 13
0 votes
1 answer
50 views

Can creating and returning a disposable object from a static class method cause memory leaks?

I've noticed a windows service taking a lot of memory and am trying to get to the bottom of the issue. I noticed that we have a static class containing a static method which is in charge of creating ...
Ponsietta's user avatar
  • 319
0 votes
0 answers
24 views

Unable to resolve "cannot make a static reference to a the non-static method getId() from the type Course" [duplicate]

Newbie learning a first REST API example in Springboot. I have this snippet in my implementation class giving the error ""cannot make a static reference to a the non-static method getId() ...
Merlion Curry's user avatar
0 votes
0 answers
20 views

Mongoose: should I use Instance methods for making changes to a reference array in a Mongoose Schema

This is a question with the purpose of finding out which way is the right way for what I want to accomplish. I'm relatively new to programming and Node.js. So apologies if I'm not using the right ...
Dubberdink's user avatar
0 votes
0 answers
17 views

Django ModelMultipleChoiceFilter - not_in method

I'm trying to set up a ModelMultipleChoiceFilter in Django, and am wondering if I'm able to pass in a method to it. The filter is meant to exclude any param values for my delivery status field, so I ...
coak's user avatar
  • 1
1 vote
2 answers
42 views

( modifier 'static' is only allowed in constant variable declarations ) compilation error

import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java....
HarshSinha_7's user avatar
1 vote
2 answers
76 views

Is there a Matlab equivalent to Pythons @classmethod?

In Matlab, I want to create an alternative constructor using a static method, and I want this constructor to be able to inherit to subclasses. I fail to do so, because I cannot get a reference to the ...
lvdgraaff's user avatar
0 votes
0 answers
36 views

Using Swift protocols extensions instead of static funcs

I have begun to see protocols and their extensions being used solely to hold general purpose functions. These funcs only use global symbols or input parameters. The code could be contained in static ...
Jeff's user avatar
  • 3,881
-1 votes
2 answers
270 views

Is there a way to reuse variables in Kotlin in static functions in multiple calls?

I just found that function params are not mutable in Kotlin. I was expecting mutability with no mention of this in official documentation I found. Personally I think there should be some way to reuse ...
maybeJosiah's user avatar
-1 votes
1 answer
74 views

What's the difference between static method inside a class and a function outside of it (JavaScript)

I don't really catch what is the purpose of putting a static method into a class and then calling it with this class instead of just creating a function with the same code. class test { static sum(...
stepaks675's user avatar
-4 votes
1 answer
69 views

How Would I Call Class1 method to Class 2 So I can Print it out on class 2

I have 2 Class here. One that creates the random number and one that prints out the random number except class 2 cannot retrieve the random number and I'm not sure why, any help? { class Class1 ...
Kizarcko's user avatar
0 votes
1 answer
247 views

How to reference static functions in Unity inspector

I have a scriptable object class Attack and created some assets from it. In the Attack asset inspector, I want to be able to reference static functions from other classes, so when something happens, I ...
Daniel's user avatar
  • 7,437
-1 votes
1 answer
171 views

Is @JvmStatic in Kotlin only usable in JVM?

With Kotlin JvmStatic is for JVM static functions. Specifically, in a companion object in a class, can I use @JvmStatic with a thing not necessarily on JVM? I have tried researching everywhere, no ...
maybeJosiah's user avatar
0 votes
1 answer
55 views

Using nested helper functions while building a class

I want to build a class which is merely a wrapper for some data. This is the basic idea: class Fruits: fruits = [ 'apple', 'orange', 'cherry' ] My fruits aren’t strings, though, but classes ...
Alfe's user avatar
  • 57.1k
0 votes
0 answers
24 views

Extend a DataTable using a helper method to convert a database response to a list of objects

I have a public Manager class that uses a repository to make calls to my database and return the data as a DataTable. Once the data is returned as a DataTable, I then pass the DataTable to another ...
Nse's user avatar
  • 305
0 votes
0 answers
29 views

Pass environment data using forRoot

I'm trying to pass environment data using forRoot, here is code example: Parent app: @NgModule({ declarations: [AppComponent], imports: [ ... SimpleModule.forRoot(...
Naor Yael's user avatar
0 votes
0 answers
39 views

May expose internal static state by storing a mutable object into a static field

There is some legacy code.. The class A has a static field, and a static method in which it's nesessary to assign a value to a static variable. spotbugs advises to store a copy of the object, not the ...
Luisian's user avatar
-1 votes
2 answers
72 views

is it bad practice the static methods/function? [closed]

Is that a bad practice to implement static function/method which only doing some arithmetic (+, -, *, /) operations or comparisons (<, <=, =>, >, !=, ==)? For example, public class Clazzy {...
L. Kvri's user avatar
  • 1,522
-2 votes
1 answer
107 views

The Value Assigned to my Number In Public Static Int Method Doesn't Get Assigned [duplicate]

While I transformed parts of my code into methods, an integer I mean to increase under a certain condition (the player score) doesn't. This is a series of methods inside other methods inside a single ...
jpeg_louie's user avatar
0 votes
1 answer
34 views

Calculating max difference between consecutive elements in a specific column of a list of lists in Python without pandas

I have array that is a list of lists. Each list index of the list is representative of a specific 'column' of data. I need to find the max difference between any two consecutive elements in 1 specific ...
jwatki8's user avatar
0 votes
2 answers
1k views

Mockito: how verify static method called in non-static method?

I have Animal.class: class Animal { int counter; public void move() { counter += getRandomNumber(1, 10); } public static int getRandomNumber(int min, int max) { return ...
jvatechs's user avatar
0 votes
1 answer
73 views

Rust: Static on trait with type params?

I'm new to Rust, so bear with me. I'm trying to create an static method for a trait which has type params. trait MyTrait<R>{} impl MyTrait{ fn exactly(to: &str)-> dyn MyTrait<&...
caeus's user avatar
  • 3,222
-1 votes
1 answer
88 views

How to make Laravel Facades use their own attributes?

I created a CalendarResource class, that I want to call statically using a Facade: <?php namespace App\Models\Shared; class CalendarResource { public function __construct( public ...
JanBoehmer's user avatar
2 votes
1 answer
140 views

Insert a message in a Blazor SignlR Chat from outside the hub

I have a standard Blazor SignalR chat. The main chat is working in a hub.class derived from Microsoft.AspNetCore.SignalR.Hub. This works fine. Now I want to insert messages from outside the hub. For ...
Daniel Schneider's user avatar
-1 votes
1 answer
119 views

My static method can't find my static inner class' static inner class

I tried to run the following code contained in my MainClass.java file, but it failed with a compilation error. public class MainClass { public static interface StaticParentType{ public ...
davidalayachew's user avatar

1
2 3 4 5
57