2,827 questions
0
votes
1
answer
59
views
Is there any way to make Groovy 4.0.x compile interfaces with static methods?
I want to make an interface with some static methods for decorating instances or adapting them to other interfaces. However, Groovy 4.0.x gives an error when trying to do this, probably because it's ...
1
vote
1
answer
76
views
Is there a language feature like Python's `issubclass` to cast instances of System.Type to the actual type (to access static methods w/o reflection)?
I have the following interface which contains a static method definition:
public interface IUpgradableDataSource
{
static abstract Task<JsonElement> UpgradeSourceConfigurationAsync(
...
1
vote
2
answers
158
views
C++ Why is it not possible to invoke functions globally without initializing new variables?
If I had to run functions in the global scope e.g. in order to populate a static container in several cpp-files, then each time such a function is invoked I would have to initialize a new variable as ...
0
votes
1
answer
59
views
Set data from WebSocket Server to JFrame components
I have WebSocket server:
@ServerEndpoint(value = "/demoApp")
public class MyWebSocketServer {
@OnMessage
public String onMessage (String message, Session session) throws IOException {...
-1
votes
2
answers
89
views
Why does Java allow static methods within an Inner class [duplicate]
Java shouldn't allow static methods within an inner class and yet this code compiles and runs. How is this possible?
class Test{
static int j=20;
public void m1() {
class Inner{
...
-2
votes
1
answer
61
views
Well Crafted Patterns To Access Instanced Members Through Static Functions Without The Singleton?
I'm looking for a solution that would allow me to have access to a static function that would operate on instanced values without implementing a singleton. I'm not sure it's possible, I've personally ...
5
votes
2
answers
83
views
Assigning an Attribute to a @staticmethod in Python
I have a scenario where I have objects with static methods. They are all built using an outside def build_hello() as class variables.
def build_hello(name: str):
@staticmethod
def hello_fn():
...
0
votes
1
answer
60
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 ...
0
votes
2
answers
583
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 ...
0
votes
1
answer
94
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 ...
-2
votes
1
answer
107
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;
}...
0
votes
1
answer
67
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 ...
0
votes
0
answers
30
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....
0
votes
1
answer
115
views
Unable to call static method supplyAsync of class CompletableFuture on object of the same class! CompletableFuture c=new CompletableFutre; c fails [closed]
In JAVA CompletableFuture is a class which contains a static method named supplyAsync() I can call this static method using CompletableFuture.supplyAsync() pattern but I am unable to call the static ...
0
votes
2
answers
259
views
How can I call a non-static function from an abstract class in PHP 8?
I want to update our current project that runs on PHP 7.2 but I got an issue that I cant resolve easily.
public function getCategories($type){...}
//In another file that dosent implements Category
$...
0
votes
1
answer
79
views
Python - polymorphism in instance methods vs polymorphism in static methods
What is the practical difference between instance methods and static methods, since these two codes return the same results? I understand that static methods do not operate on ‘self’ and do not have ...
0
votes
2
answers
82
views
Is this the correct use of staticmethods?
Suppose I have two classes A and B, where B inherits from A. A and B both have a bar method. A has a foo method which is inherited by B.
I now want bar from A to be called whenever foo is called, ...
-2
votes
1
answer
71
views
multiple definition and static keyword
the function f in 2.o have global scope, and 1.c if he wanted he could use it.
but in 1.o have unique definition of f.
the linker agree to accept it though
How is there no conflict here and which ...
1
vote
0
answers
91
views
Having named constructors while avoiding their use as a method?
I really like the syntax of "named constructors," which I understand to be static methods that return the object hosting them? (I apologize if "named constructors" isn't the right ...
0
votes
1
answer
215
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.
...
0
votes
1
answer
48
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....
-1
votes
1
answer
33
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 {
@...
-1
votes
1
answer
143
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 ...
0
votes
0
answers
27
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. ...
1
vote
0
answers
92
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 ...