I'm having some problems trying to figure out how to solve a problem without being able to have static method in an abstract class or interface. Consider the following code. I have many Wizards that inherit from AbsWizard. Each wizard has a method GetMagic(string spell) that only returns magic for certain magic words, yet all instances o...
In java I sometimes use class variables to assign an unique id to each new instances. I do something like:
public class Foo {
private static long nextId = 0;
public final long id;
public Foo() {
id = nextId;
nextId++;
}
[...]
}
How can I reproduce this behaviour in scala ?
...
Hi folks,
I got a prob that, I have a base static library "Base", then other 2 libs("A" & "B") depend on it. So then I have a project "P", I add the 3 libs to "P", I get an error:
ld: duplicate symbol .objc_category_name_NSObject_IMIBase in
/Users/Travis/Documents/Home/IMI/IMIKit/build/Debug-iphonesimulator/libIMIUI-iphonesimulator.a(...
I have a static SessionFactory class that initializes an NHibernate session factory. Because this process is expensive (~5 sec.), I want it to be static so it's only done once, at the beginning of runtime.
The configuration can take a database parameter parameter like so:
public static IPersistenceConfigurer DbConfig { get; set; }
pub...
All I want to do is make sure that child classes of the class Item implement a static method and I want this to be checked at compile time to avoid runtime errors.
abstract classes with static methods don't seem to work:
ERROR: A static member
cannot be marked as
override, virtual, or abstract
public abstract class Item
{
...
Possible Duplicate
http://stackoverflow.com/questions/370283/why-cant-i-have-a-non-integral-static-const-member-in-a-class
struct Example
{
static const int One = 1000; // Legal
static const short Two = 2000; // Illegal
static const float Three = 2000.0f; // Illegal
static const double Four = 3000.0; // Illegal
...
Recently I have observed the following interesting scenario in one of the application I'm developing using .NET 3.5. In this particualr application I have a singletion object which I access as a static variable. I exepected that the .NET run time should initializes this singleton object at the very first time I access it, but it seems th...
Let's say that I create an instance of class B, which has an static variable x, assigned with a value of 3 in the class B declaration. In the main() method, I do this:
B b = new B();
b.x = 7; //allowed to use an instance to set the static member value
After this, b is serialized and then de-serialized. Then, the following line occurs:...
Okay, I'm trying to write a program that will scan a bunch of words to match against a set of letters. I want all words displayed that contain the letters entered by the user and I want these words displayed while the program is still searching. Therefore, I have to split the search onto its own thread, separate from the UI thread. Ea...
I understand that in this code:
class Foo {
public static void method() {
System.out.println("in Foo");
}
}
class Bar extends Foo {
public static void method() {
System.out.println("in Bar");
}
}
.. the static method in Bar 'hides' the static method declared in Foo, as opposed to overriding it in the ...
Hi,
Is it possible to return in a static method a class? I will explain...
I have:
public class A { public static void blah(){} }
public class B { }
I want to create a static method in B witch returns A. So you can do:
A.blah();
And
B.getA().blah();
This, without creating an instance of A. Just use it static methods.
Is this ...
I've recently found the resx resources feature of C#/VS2008. However, I have trouble finding information about what they are normally used for.
For example, I want to have a "static string" defined somewhere in my project, such as a CSS class that should be used in certain circumstances. Is it a good idea to define that string as a reso...
Hello,
I need to keep a list(vector) of children for every class, and I've got a tricky problem:
class A
{
protected:
int a;
static vector<A*> children;
public:
A(int a): a(a) {;};
virtual void AddToChildren(A* obj);
virtual void ShowChildren();
virtual void Show();
};
class B: public A
{
protected:
int...
I have a Java class that only consists of static member variables and static methods. It is basically serving as a utility class. Is this a bad practice to have a class that only consists of static member variables and static methods?
Thanks
Steve
...
I am creating event search application, we set search criteria from one screen populate in another screen then user can edit search criteria from 3rd screen and goes to 4th screen.
To achieve above task i am using static object which remember the values around the application and i don't need to do any thing extra.
But i am afraid if a...
Here's a piece of my code:
public class MyClass {
public object Value { get; set; }
public MyClass(object value) {
this.Value = value;
}
}
public class AnotherClass {
private static MyClass _MyObj = new MyClass(new object());
public static void Main(string[] args) {
var x = _MyObj; // no problem
var y = x.Value;...
I am writing a class library(API) in C#. The class is non-static and contains several public events. Is it possible to trigger those events from a static method in a separate class?
For example...
class nonStaticDLLCLASS
{
public event Event1;
public CallStaticMethod()
{
StaticTestClass.GoStaticMethod();
}
}
class Stati...
I'm building an ASP.Net website. I have a "cart" class which stores the items in the users cart. I don't want to re query the database every time the page reloads to populate the cart items stored in this object. Is the best way to store/persist instantiated objects by putting them in a session and store the session to a database (we're ...
Hi guys,
I'm working on a video player and I initially developed the player with everything in the .FLA file with no classes. Then I started modularizing my player into classes and realised that my classes are static methods rather than instance methods which doesn't seem to be needed in my player. My question is - is this a bad design ...
class Interface {
public:
static const int i = 1;
static const double d = 1.0;
//! static const string *name = new string("Interface name");
virtual string getName() = 0;
}
Since C++ is a traditional truely compiled programming language,it could be easily convinced that it does allow object initialization(?).But why do C++...