Skip to main content
The 2024 Developer Survey results are live! See the results

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.

-6 votes
0 answers
27 views

Need assistance with adding a piece of code to my current one [closed]

[Screenshot of missingtext]Screenshotofprinted (https://i.sstatic.net/oZB8vrA4.png) Hello I am just learning and very new to Java so apologies if my code is a mess. I am supposed to use toString, ...
CrownVic's user avatar
-1 votes
0 answers
25 views

c++: define static template method in non-template class (with header file) [duplicate]

I've seen many questions in this regard, but non seems to be facing this below issue, I'm new to C++ and I hope someone has an answer for below. below code works fine (in one file): main.cpp class BB{ ...
Abdullah D.'s user avatar
1 vote
1 answer
76 views

How to provide a 'blanket implementation' of a static method for the derived class?

Consider this: struct Base { static Base make() { return {}; } }; struct Derived : public Base { // I _would_ want to have a `static Derived make()` automagically here }; One approach to the ...
Mike Land's user avatar
  • 480
0 votes
1 answer
46 views

DRY - Derived class with static methods

In Unity C#, I have a base class Baker, it's derived from ScriptableObject, and I'm deriving from it CakeBaker, BreadBaker, PieBaker. ScriptableObjects can only be created statically, using ...
TheUmpteenth's user avatar
0 votes
1 answer
58 views

Importing a static method when not using a project structure [duplicate]

I'm trying to import the static method my_function into Main: Main.java: import static abc.my_function; // error public class Main { public static void main(String[] args) { my_function();...
Joy's user avatar
  • 81
0 votes
2 answers
91 views

Get the caller function object when it's a static method

I thought I knew a bit of Python, but then I stumped on this (a distilled form follows): class A: @staticmethod def f(): print('some code here to report exactly who ...
sl2c's user avatar
  • 11
1 vote
0 answers
20 views

How to add type definition on a single class which contains both static and instance properties/functions in TypeScript? [duplicate]

I was trying to follow this tutorial to try and answer my question initially, but it's not enforcing that I have implemented the static functions in my code. Here is what I have: export type ...
Lance's user avatar
  • 77.9k
0 votes
1 answer
83 views

Static methods in Java interfaces to be implemented by classes that implement the interface

I know that it is possible to define static methods in Java interfaces that are bound to the interface itself. However, I would like to define the signature of a static method to be implemented by ...
pbp's user avatar
  • 49
0 votes
2 answers
98 views

How to add a type hint to a variable representing self in a static method within a class

I'm trying to add type hints to a static method in Python using typing.Self. However, the type hint isn't being applied to the self argument within the function itself. from typing import Self class ...
Sahan 's user avatar
  • 106
-2 votes
1 answer
36 views

C# kind of extension method for static function [duplicate]

With extension method, it is possible to add function that you call an instance. public static class MyExtensions { public static bool MyNewExtension(this String s) { return true; }...
gbs69's user avatar
  • 35
1 vote
1 answer
153 views

Efficiency advantage of C++ 23 static operator()

I'm looking at the motivation for static operator() laid out in this article https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1169r2.html where they explain that function objects, frequently ...
Gonen I's user avatar
  • 5,989
0 votes
1 answer
38 views

In a Dart (Flutter) class extending an abstract, how can an instance reference a static method (e.g. tableName)?

This is not quite the same as this question, which itself is unanswered. I want to call get the tableName from inside an instance when the instance is an interface. Currently, I have it as an instance ...
Richard Haven's user avatar
0 votes
0 answers
39 views

How to mock a static method that modifies an input and returns Unit with Mockk

I'm trying to use Mockk to mock the static method android.location.Location.distanceBetween(). Here's my test case: class DistanceUtilsTest { @Before fun setup() { MockKAnnotations....
toshiomagic's user avatar
  • 1,527
0 votes
0 answers
17 views

Static comparison function results in heap buffer overflow

class Solution { private: static bool cmp(const int& a, const int& b) { return a >= b; } public: long long function(vector<int>& nums) { sort(nums....
Shashank Bhari's user avatar
2 votes
3 answers
91 views

What kind of PHP syntax is this? [duplicate]

Can you please tell me what kind of PHP syntax is: echo Html::{'div.my-class#my-id'}('This is element content') ? It's from https://github.com/decodelabs/tagged library. I mean I know what it does, ...
Michał Grabowski's user avatar

15 30 50 per page
1
2 3 4 5
189