static-members

Are Static classes thread safe

[亡魂溺海] 提交于 2019-12-09 02:39:45
问题 I have gone through msdn where it is written that all the static classes are thread safe. Well that article is meant for version 1.1... http://msdn.microsoft.com/en-us/library/d11h6832(v=vs.71).aspx All public static members (methods, properties, fields, and events) within the .NET Framework support concurrent access within a multithreaded environment. Therefore, any .NET Framework static member can be simultaneously invoked from two threads without encountering race conditions, deadlocks, or

need of Static variables and their overhead on jvm

江枫思渺然 提交于 2019-12-09 01:21:37
问题 As per the concept about static members, they are created/loaded into the memory when there is first call made to its class. And they are common among all instances of that class. Means they are not re-created or re-itialized etc. In addition, They can be accessed by the class name only. There is no need to create object for that class just to access them. Now my questions are; Whether static members ever be in memory till the application is running? even if all the instances of that class

Write to static field - is FindBugs wrong in this case?

不打扰是莪最后的温柔 提交于 2019-12-08 17:26:40
问题 I have a Java class like this: public class Foo { public static int counter = 0; public void bar(int counter) { Foo.counter = counter; } } FindBugs warns me about writing to the static field counter via the instance method bar . However, if I change the code to: public class Foo { public static int counter = 0; public static void setCounter(int counter) { Foo.counter = counter; } public void bar(int counter) { setCounter(counter); } } Then FindBugs won't complain. Isn't that wrong? I'm still

Have I found a bug in Clang?

谁说我不能喝 提交于 2019-12-08 15:09:25
问题 I tried to compile the code below with Clang class Prasoon{ static const int dummy = 0; }; int const Prasoon::dummy = 0; int main(){} The above code did not give any error when compiled with Clang. prasoon@prasoon-desktop ~ $ clang++ --version clang version 2.8 (trunk 107611) Target: i386-pc-linux-gnu Thread model: posix prasoon@prasoon-desktop ~ $ cat bug.cpp class Prasoon{ private: static const int dummy = 0; }; int const Prasoon::dummy = 0; int main(){} prasoon@prasoon-desktop ~ $ clang++

Partial template specialization for initialization of static data members of template classes

前提是你 提交于 2019-12-08 12:28:44
问题 How would one initialize static data members of a template class differently for particular parameters? I understand that templates are different than other kinds of classes and only what is used in the project ever gets instantiated. Can I list a number of different initializations for different parameters and have the compiler use whichever is appropriate? For example, does the following work, and if not what is the correct way to do this? : template<class T> class someClass { static T

ES6 classes, member properties definitions as static/shared

一曲冷凌霜 提交于 2019-12-08 09:18:30
问题 I am testing classes in ES 6 with io.js 2.xx the example below I took from Mozilla, Things are getting on tracks (OOp in JS), at least we now have direct inheritance (at syntax level) with the 'extends' directive... the problem I pose is that member properties are defined inside constructor this is at least a syntax problem... (been searched through the web and found very few information about this) will be more a of a problem when ESxx try to had visibility directives to property members (in

Static member error in c++

别来无恙 提交于 2019-12-08 02:23:40
问题 I am trying to define a static member pointer in C++. However I get a linker error. The error is 1>main.obj : error LNK2001: unresolved external symbol "public: static class Activity * * Solution::temp" (?temp@Solution@@2PAPAVActivity@@A) 1>Solution.obj : error LNK2001: unresolved external symbol "public: static class Activity * * Solution::temp" (?temp@Solution@@2PAPAVActivity@@A) Code: class Solution{ public: Activity **solution; Solution(); Solution(Activity **list, bool direction); static

Why might a static data member not get initialized?

拟墨画扇 提交于 2019-12-07 04:12:35
问题 I'm trying to register a bunch of classes with a factory at load time. My strategy is to harness static initialization to make sure that before main() begins, the factory is ready to go. This strategy seems to work when I link my library dynamically, but not when I link statically; when I link statically, only some of my static data members get initialized. Let's say my factory builds Cars. I have CarCreator classes that can instantiate a handful of cars, but not all. I want the factory to

Static initialization of inherited static member

牧云@^-^@ 提交于 2019-12-07 03:13:01
问题 Consider this example code: public class A<T> { public static T TheT { get; set; } } public class B : A<string> { static B() { TheT = "Test"; } } public class Program { public static void Main(String[] args) { Console.WriteLine(B.TheT); } } Here B.TheT is null. However, changing the Main method like this: public static void Main() { new B(); Console.WriteLine(B.TheT); } B.TheT is "Test", as expected. I can understand that this forces the static constructor to run, but why does this not happen

Get value of static field

北城以北 提交于 2019-12-07 01:07:42
问题 I've got the following class: public static class Pages { public static string LoggedOut = "LoggedOut.aspx"; public static string Login = "Login.aspx"; public static string Home = "Home.aspx"; } I know I can use Pages.Home statically, but there is a reason for my question. I wish to have a method that I can call like this: string pageName = Pages.GetPage("Home"); etc. C'est possible? Thanks, Dave 回答1: You can use the following: var field = typeof(Pages).GetField("Home", BindingFlags.Public |