static

How come invoking a (static) method on a null reference doesn't throw NullPointerException?

I wrote this program in Java public class Why { public static void test() { System.out.println("Passed"); } public static void main(String[] args) { Why NULL = null; NULL.test(); } } I read that invoking a method on a null object causes NullPointerException, and yet the above program doesn't? Why is this? Am I n...

C++ class declared as static class member

Is there any problem with declaring a class with a static member which is another class in a header. E.g: class Stat { public: int avar; Stat(); }; class Test { public: static Stat stat; }; The reason I fear it might cause problems is that it seems very similar to declaring a global variable in a header. If included in tw...

problem with weblogic static timer

hi all i have written a JSF project. in my project i am using some java timers in my backbean private static List<PollerTimerTask> tasksList; every things work fine, but when i am changing my project and redeploy it by ANT the active timers continue to work but my static field is become null. what is wrong? how can i fix this? i a...

change private static final field using java reflection

I have a class with a private static final field, that unfortunately i need to change at run time. using reflection i get this error: java.lang.IllegalAccessException: Can not set static final boolean field is there any possibility to change it anyway? Field hack = WarpTransform2D.class.getDeclaredField("USE_HACK"); hack.setAccessible...

force a new address space for a function (make static variables unstatic)

I got a function in a file that works for a single function call. But since it depends on alot of static declarations within this file (I didn't make this file, and its to big to modify). It wont work with multiple function calls. Is there some way to make each function call unaware of previous calls, or current calls? In effect force a...

How to override a static property of a parent object and let the parent object access the new value in PHP?

This is what I have: All objects that can be persisted on the database extend the DatabaseObject abstract class, which has all the logic code to actually watch for attribute changes and run the databas queries. I'm using two static variables to define object-specific details. I define them generically in the base class, and then suppose...

Static const member initialization in templated class

I have a problem regarding 'static const' member initialization. In a templated class I define a const member and initialize it outside the class. When I include the .h file where this class is implemented in multiple .cpp files, I get an LNK2005 error (I'm using VS2010) that says the constant is already defined. // List.hpp template <...

Objective-C parser problems with and static getter-function

Hi there, I've created a static getter-function: @implementation MyClass static int aValue = 1; + (int) aValue { return aValue; } // other stuff here @end and now I'm trying to access it in some different ways from another class: @implementation AnotherClass - (void) aMethod { if (MyClass.aValue > 0) { NSLog(@"Foobar"); } //...

Singletons in Google App Engine can get expired, or does that many that any static variable can get expired? (java)

I read that in Google App Engine there is a chance that a singleton class might die, if the application gets idled for too long (or a new application instance is created), and I have experienced this myself. But does that really mean that Any static variable in any class might get expired in the application? or how can GAE identify that...

PHP Static class initializer

I have an helper class with some static functions. all the functions in the class requires a 'heavy' initialization function to run once ( like it was a constructor.. ). is there a good practice ? the only thing i thought of is calling 'init' function , and breaking it's flow if it already run once (using static $initialized var). pro...

Python - Referencing class attribute from another class attribute

In python, I want to have a class attribute which is a dictionary with initialized values. I wrote the code like the below. class MetaDataElement: (MD_INVALID, MD_CATEGORY, MD_TAG) = range(3) mapInitiator2Type = {'!':MetaDataElement.MD_CATEGORY, '#':MetaDataElement.MD_TAG} But when I try to run this c...

Simple syntax for getting a member of a type in extension method (C#)

I'm trying to write an extension method that will give me the MemberInfo representing a member of a given type, using lambda expressions. Ideally, I'd like to be able to write var info = MyType.GetMember(m => m.MyProperty); or, also acceptable var info = typeof(MyType).GetMember(m => m.MyProperty); or even var info = typeof(MyType...

php class static variables ,concat

is have 2 class first <?php require_once( 'error/DisconnectedHandler.php' ); require_once( 'error/NoSuchRequestHandler.php' ); class NetworkManager { public static final $RESPONSE_JUMP = 1000; .... second <?php require_once( '../NetworkManager.php' ); class DisconnectedHandler implements Handler{ pu...

accesing static variable in php

hey there i have a simple case of class with static variable and a get function all compile ok but at run time i am getting this error [Sun Jul 25 03:57:07 2010] [error] [client 127.0.0.1] PHP Fatal error: Undefined class constant 'TYPE' in ..... for the function getType() here is my class class NoSuchRequestHandler implements ...

Duplicate Symbol XCode duplicate library for same library?

Do you have any idea? Why XCode compilation give this result? ld: duplicate symbol _kJSONDeserializerErrorDomain in /Users/Shared/_BUILDS_/Debug-iphoneos/libLACDLibrary.a(CJSONDeserializer.o) and /Users/Shared/_BUILDS_/Debug-iphoneos/libLACDLibrary.a(CJSONDeserializer.o) ...

Static Variable Pointer?

Is this illegal/dangerous? int* static_nonew() { static int n = 5; return &n; } The compiler doesn't seem to have a problem with it, but is the pointer location itself protected from being overwritten when someone else needs memory? EDIT: A little bit more of an explanation of why I asked this question. Note: I'm programming ...

Encapsulating generic database methods in a Java superclass and then calling from Child classes doesn't work without a cast. HELP

I'm having a heap of trouble with Java coming from a PHP background. I've got a parent class Entity containing generic database methods, such as a static method getById(int id). My aim is to have children of this class, such as Person, so that I can call: Person p = Person.getById(1); At the moment this doesn't work, as getById(1) re...

Huge Static Array of String

Hi, Is it a good idea to store words of a dictionary with 100.000 words in a static array of string. I'm working on spellchecker and I thought that way would be faster. ...

Assembly creation guidelines

Is there any rule of the thumb as to the number of static functions you can have in an assembly? How do you recognize if a function needs to be static v/s a function that doesn't need to be static? ...

is it possible to have multiple instances of static variables

Static variables have only instance (that is they are part of the class). ex: Math.pi Is there any way there could be multiple instances of static variables? I heard there is something related to Classloaders? ...