Hey guys,
Im having a problem with using a variable as the class name when calling a static function within the class. My code is as follows:
class test {
static function getInstance() {
return new test();
}
}
$className = "test";
$test = $className::getInstance();
Ive got to define the class name to a variable a...
I'm refactoring some code and I'm looking at a class called HFile. HFile has all private constructors so that you can actually create instances of it. Instead of creating instances of HFiles as follow:
var file = new HFile('filename')
file.Save()
All HFile interaction is handled via static methods. So if I wanted to save a file I w...
I know it's wired to have such a case but somehow I have it:
class foo
#static method
@staticmethod
def test():
pass
# class variable
c = {'name' : <i want to reference test method here.>}
What's the way to it?
Just for the record:
I believe this should be considered as python worst practices. Using static methods is ...
Why is it not possible to override static methods?
If possible, please use an example.
...
public class CallingStaticMethod {
public static void method() {
System.out.println("I am in method");
}
public static void main(String[] args) {
CallingStaticMethod csm = null;
csm.method();
}
}
Can someone explain how the static method is invoked in the above code?
...
Hi,
I'm a beginner programmer, and am wondering how to work around this issue. The problem I am trying to solve is keeping a tally of static method calls in my program using a java.util.Observer.
Clearly, my original post must have just confused people so I'll leave it more open-ended: can anyone suggest a way to keep a static method ...
Hey,
I'm using Linq to SQL for my DAL and have heard various things about using static methods in a web application (regarding threading/concurrency issues). At the moment, I created a test DAL, which seems to be functioning fine. However, are there any problems with the way I've created it, since it's static?
public static class ...
I have a static function in a class.
whenever I try to use non static data member, I get following compile error.
An object reference is required for the nonstatic field, method, or property member
Why is it behaving like that?
...
I have this method that I want to use $this in but all I get is: Fatal error: Using $this when not in object context.
How can I get this to work?
public static function userNameAvailibility()
{
$result = $this->getsomthin();
}
...
Okay, the post title might be a little confusing.
I have this code:
class A {
public static foo() {
return get_called_class();
}
}
class B extends A {
}
class C {
public function bar() {
echo B::foo();
}
}
Output: C
WHat I want to get in foo() is the class name of B. How can I do this without chang...
What does it mean?
Having a non-static class which has for example one static method?
Without creating an instance of that class, we can't use it. But What about its static method?
...
Hello, everyone!
I thought, I would understand Java generics by now. But now I'm helpless again.
I have a generic class where a c-tor constructs correctly-typed instance, while a static factory method produces a type mismatch.
Please look at the following code:
public class _GenericFactoryMethods {
public final static class DemoCl...
Let's say I have a static method called Logger.log(), which calls another static method, CurrentUser.getName(), to get some additional information to log:
public static void log(text) {
String[] itemsToLog = { text, todaysDate, ipAddress, CurrentUser.getName() };
Now obviously this isn't an ideal situation, especially with the stati...
How does C#, or other languages for that matter, handle memory allocation (and memory de-allocation) between these two scenarios:
1.) A method on a static class is invoked.
public Program {
Foo foo = Loader.load();
}
public static Loader {
public static Foo load() {
return new Foo();
}
}
2.) A method is invoked...
Hi,
I am using a third party library to do hand evaluation of 7 card poker hands. The method evaluate in this library is declared as public static and I believe it alters some global static arrays within the class. The problem I have is that as I am doing an enumeration algorithm of about 10m enumerations I want to parallelize it, there...
I'm currently rewriting an e-shop - but only the client side, i.e. the CMS remains mostly in tact. I am not using a pre-built framework, as the system has to retain backwards compatibility with the CMS and I have to have full freedom of the structure of code.
The new system is purely MVC based and I have a Bootstrapper which loads cont...
Hi,
If I have a large .NET method, I want to know if it is good practice to split it up into multiple methods or not. My concerns are:
1 - Is there any point creating a method if it will only be called once?
2 - If I'm calling a private method from within my class, I try not to use instance variables. Is this good or bad practice? Fo...
I have a static class with serveral static methods. In these methods, I'm trying to access the current thread's context using HttpContext.Current. For example:
var userName = HttpContext.Current.User.Identity.Name;
However, when I do that, I receive a NullReferenceException, the infamous "Object reference not set to an instance of an ...
When a class is defined as a private static, why do I need to make the get and set methods static?
...
I'm trying to expand my sons interest from Warcraft 3 programming into C++ to broaden his horizons to a degree. We are planning on porting a little game that he wrote.
The context goes something like this.
There are Ships and Missiles, for which Ships will use Missiles and interact with them
A Container exists which will hold 'a list...