Duplicate: http://stackoverflow.com/questions/413898/what-does-the-static-keyword-do-in-java
I've read this post already.
What does the "static" keyword in a method do?
I remember being told that static != clingy...but that is pretty much all I know about this keyword.
...
So this seems pretty basic but I can't get it to work. I have an Object, and I am using reflection to get to it's public properties. One of these properties is static and I'm having no luck getting to it.
Public Function GetProp(ByRef obj As Object, ByVal propName as String) as PropertyInfo
Return obj.GetType.GetProperty(propName)...
Given an hypothetical utility class that is used only in program setup:
class MyUtils {
private static MyObject myObject = new MyObject();
/*package*/static boolean doStuff(Params... params) {
// do stuff with myObject and params...
}
}
will myObject be garbage collected when it is no longer being used, or will it stic...
I'm working with some code that widely uses the idiom of returning a pointer to a static local variable. eg:
char* const GetString()
{
static char sTest[5];
strcpy(sTest, "Test");
return sTest;
}
Am I right in thinking that this is safe?
PS, I know that this would be a better way of doing the same thing:
char* const GetString...
Let's say I have some Java code:
public class SomeClass {
static {
private final double PI = 3.14;
private final double SOME_CONSTANT = 5.76;
private final double SOME_OTHER_CONSTANT = 756.33;
}
//rest of class
}
If a thread is instantiating an instance of SomeClass and is in the middle of initializi...
I'm just starting out with C# and to me it seems like Microsoft Called their new system .Net because you have to use the Internet to look everything up to find useful functions and which class they stashed it in.
To me it seems nonsensical to require procedure/functions written and designed to stand alone ( non instantiated static obje...
I want to create a static class in PHP and have it behave like it does in C#, so
Constructor is automatically called on the first call to the class
No instantiation required
Something of this sort...
static class Hello {
private static $greeting = 'Hello';
private __construct() {
$greeting .= ' There!';
}
p...
Can I control the order static objects are being destructed?
Is there any way to enforce my desired order? For example to specify in some way that I would like a certain object to be destroyed last, or at least after another static onject?
Cheers,
Gal
...
I am creating a portal where many sites will run of the same MVC application. I have a list of Sites stored in the HttpRuntime.Cache. Is it wrong to access the cache via a static method? Should I instead be passing this on view data?
For example, is this wrong on the view:
<%= SiteHelper.CurrentSite %>
Where the code for SiteHelper is...
I was working with a Lisp dialect but also learning some Haskell as well. They share some similarities but the main difference in Common Lisp seems to be that you don't have to define a type for each function, argument, etc. whereas in Haskell you do. Also, Haskell is mostly a compiled language. Run the compiler to generate the execu...
I have to implement a set of 60 functions, according to the predefined signatures. They must be global functions, and not some class's member functions. When I implement them, I use a set of nicely done classes provided by 3rd party.
My implementation of most functions is quite short, about 5-10 lines, and deals mostly with different ac...
Our group has a "tools library" DLL that several of our internal projects
(all C#) make use of. I've developed the intuition that a good chunk of
the tools library is used only by one of the projects -- let's call that
project "Project A". Are there any .NET tools that can examine the
tools DLL and all the projects (maybe the project EXE...
I followed the steps here but i'm unable to run static analyzer on my project:
Finding memory leaks with the LLVM/Clang Static Analyzer
When i try to run xcodebuild on my project (1. Open Terminal, 2. Go to Project Directly, 3. > xcodebuild), i get this error:
=== BUILDING NATIVE TARGET XProject OF PROJECT XProject WITH THE DEFAULT...
A bit of backstory: I am working on an web application that requires quite a bit of time to prep / crunch data before giving it to the user to edit / manipulate. The data request task ~ 15 / 20 secs to complete and a couple secs to process. Once there, the user can manipulate vaules on the fly. Any manipulation of values will require...
I'm trying to create a cache in a webservice. For this I've created a new Stateless Bean to provide this cache to other Stateless beans. This cache is simply a static ConcurrentMap where MyObject is a POJO.
The problem is that it seems as there are different cache objects. One for the client beans, and another locally.
-CacheService
-Ca...
I'm attempting to access member variables in a child class via the parent class without instantiation.
This is one of my attempts but B::getStatic() fails with Access to undeclared static property.
Is there another solution to this, possibly without static?
class A {
static public function getStatic() {
return self::$myS...
I am reading Josh Bloch's book Effective Java and he suggests using a builder design pattern when building objects that have large amounts of members. From what I can see it isn't the vanilla design pattern but looks like his variation. I rather like the look of it and was trying to use it in a C# web application that I am writting. This...
struct TimerEvent
{
event Event;
timeval TimeOut;
static void HandleTimer(int Fd, short Event, void *Arg);
};
HandleTimer needs to be static since I'm passing it to C library (libevent).
I want to inherit from this class. How can this be done?
Thanks.
...
What real (i.e. practical) difference exist between a static class and a singleton pattern?
Both can be invoked without instantiation, both provide only with one "instance" and neither of them is threadsafe. Is there any other difference?
...
Static variable gotcha in php
I am from Java background and have switched to php for one project recently.
I have found one unexpected behaviour in php.
Value set to some static variable is
not staying persistent across the
requests.
I am not sure if this is the expected bahaviour. Because in java , you can always persist ver...