In Java, when should static non final variables be used?
For example
private static int MY_VAR = 0;
Obviously we are not talking about constants here.
public static final int MY_CONSTANT = 1;
In my experience I have often justified them when using a singleton, but then I end up needing to have more than one instance and cause myse...
Should C# methods that can be static be static?
We were discussing this today and I'm kind of on the fence. Imagine you have a long method that you refactor a few lines out of. The new method probably takes a few local variables from the parent method and returns a value. This means it could be static.
The question is: should it be sta...
Duplicate
http://stackoverflow.com/questions/731763/should-c-methods-that-can-be-static-be-static
Other then the obvious downsides of inheritance and variable scope, if you have a method that is completely contained should you always declare it as static? Are there any downside to declaring methods as static? Especially in terms ...
Hi,
I've created a class which holds a bunch of properties values.
In order to initialize that class, I have to call some static method "configure()" which configures it from an XML file.
That class was supposed to act to store some data such that I could just write
PropClass.GetMyProperty();
I call the configure() from a static b...
Duplicate:
C++: undefined reference to static class member
If I have a class/struct like this
// header file
class Foo
{
public:
static int bar;
int baz;
int adder();
};
// implementation
int Foo::adder()
{
return baz + bar;
}
This doesn't work. I get an "undefined reference to `Foo::bar'" error. How do I access stati...
A collegue of mine at work gave a presentation on static factory methods (right out of Effective Java), and then gave an example of its use for obtaining static / singleton exceptions.
This set off a red flag for me. Aren't exceptions stateful? Aren't they populated by the JVM for stack trace info? What savings do you really get wi...
I have several classes that do not really need any state. From the organizational point of view, I would like to put them into hierarchy.
But it seems I can't declare inheritance for static classes.
Something like that:
public static class Base
{
}
public static class Inherited : Base
{
}
will not work.
Why have the designers of t...
Hello.
I have some questions about initializing a static collection. Here is an example I coded that seems to work:
#include <stack>
#include <iostream>
using namespace std;
class A
{
private:
static stack<int> numbers;
static stack<int> initializeNumbers();
public:
A();
};
A::A() { cout << numbers.top() <<...
I know what it means when declared in source file. I reading some code, find that static function in header files could be invoke in other files.
...
Hello,
I am working on creating and linking shared library (.so). While working with them, many questions popped up which i could not find satisying answers when i searched for them, hence putting them here. The questions about shared libraries i have are:
1.) How is shared library different than static library? What are the Key differ...
I've seen a lot of discussion about this subject on here.
If i have a static class w/ static methods that connects to a database or a server, is it a bad idea to use this in a multi-user environment (like a web page)? Would this make a new user's tread wait for previous users' threads to finish their calls before accepting a new one?
...
Here's what I am trying to determine...
I have a utility class to append lines to a textfile.
This must be used by a number of other classes, like
a common logging file.
In my first implementation, I had all the classes
that wanted to use it make a referenceless instance, e.g.
new Logger(logline,logname);
The constructor creates a Pr...
Hello, I recently had to program C++ under Windows for an University project, and I'm pretty confused about static and dynamic libraries system, what the compiler needs, what the linker needs, how to build a library ... is there any good document about this out there? I'm pretty confused about the *nix library system as well (so, dylibs,...
I want to be able to initialize a vector of a size 'SIZE' before main. Normally I would do
static vector<int> myVector(4,100);
int main() {
// Here I have a vector of size 4 with all the entries equal to 100
}
But the problem is that I would like to initialize the first item of the vector to be of a certain value, and the othe...
I'm a C/C++ programmer recently working in C#, and i'm trying to do some fancy initialization stuff that I've run into some trouble with.
The best and easiest example i can come up with would be that I want to create an "Eager" Singleton - one that is created immediately at program startup, but without me requiring to go into the main f...
I have a Set class (This is J2ME, so I have limited access to the standard API; just to explain my apparent wheel-reinvention). I am using my set class to create constant sets of things in classes and subclasses. It sort of looks like this...
class ParentClass
{
protected final static Set THE_SET = new Set() {{
add("one");
...
I'm writing a static class for logging to be used across my developed solution. There are several components that will use it such as a console application, ASP.NET application, etc...
For the logging to work, it needs to do some initial startup configuration before it can be used, and also some clean up when each application has finish...
I would like to share an object between various instances of objects of the same class.
Conceptually, while my program is running, all the objects of class A access the same object of class B.
I've seen that static is system-wide and that its usage is discouraged. Does that mean that if I've got another program running on the same JVM ...
Code
static void MyClass::ThreadEntryStatic()
{
//...
}
void MyClass::Begin()
{
CreateThread(..,ThreadEntryStatic,..);
}
In which condition we should use the static in class ?
...
As per the question.
In the debug view, there's the Variables frame. It shows all the values of member variables of the current object, and all of the local variables, but it doesn't show any static variables of the object's class.
How do I get to these?
Some googling has suggested I press the button on the toolbar, but there's nothing...