Questions tagged [static-initialization]

Questions regarding initialization code of static members

292 questions
0
votes
1 answer

JUnit: initialization of static final attributes

Oftentimes in my unit tests I have fixtures that are read from resource files and stored into a static attribute on the test class: public class TestFoo { private static String fileContents; @BeforeClass public static void setup()…
Adam Parkin
  • 14,883
  • 13
  • 57
  • 81
0
votes
3 answers

Why is static initialization order STILL unspecified?

Doesn't a compiler have all the information it needs to generate a dependency tree of all globals and create a well defined and correct initialization order for them? I realize you could write a cyclic dependency with globals - make only that case…
David
  • 25,830
  • 16
  • 80
  • 130
0
votes
1 answer

Static initializer of shared library inside dynamic library

So I have a static library (MacOS, .a library). It's written in C++ and has static initializers in it's code like that: //myclass.hpp class MyClass { ... static MyClass *defaultValue_; static MyClass *newInitialDefaultValue(); …
peetonn
  • 2,623
  • 4
  • 23
  • 37
0
votes
6 answers

Constructors called due to static initialization

I am going through Thinking in Java by Bruce Eckel 4th Edition. In the chapter Initialization & Cleanup, page : 189 the first bullet point in the second para mentions: Even though it doesn't explicitly use the static keyword the constructor is…
gudge
  • 1,003
  • 2
  • 15
  • 30
0
votes
1 answer

How to know if Static Block Initialization has been run?

I am trying to get rid of some memory leaks. I'd like to reset all the static variables of all the classes (not only mine) from a class loader. There is a classes attribute that lists all the classes known by the ClassLoader. So I just want to loop…
poussma
  • 6,375
  • 2
  • 37
  • 63
0
votes
1 answer

How to initialize static field in template class with type of inner class

I have something like this template class Outer { public: class Inner; static Inner* x; //... class Inner { //... }; }; // Not working template Outer::Inner* Outer::x = NULL; Error I get…
abc
  • 2,291
  • 3
  • 23
  • 33
0
votes
1 answer

Powermock - @SupressStaticInitializationFor is not working

I have a class containing native methods and a static initializer which loads a dll and mocked it with powermock so that the the static initializer should be suppressed and the dll shouldn't be loaded. The class looks like this: class…
BeWu
  • 1,547
  • 1
  • 11
  • 20
0
votes
1 answer

Easiest way to locate a static variable in code?

I have a bug on my plate to locate and rewrite a static variable in one of our libraries that is taking up launch time in our application. I am not familiar with the library code base and am asking for good heuristics/techniques/grep commands/etc.…
fbrereto
  • 34,250
  • 17
  • 118
  • 176
0
votes
1 answer

What if a static initializer in class X invokes a method in Y, but Y's static initializers invoke a method in X to set up its static values?

This question is asked and explained in JAVA PROGRAMMING LANAGUAGE book.But i m not clear with explaination. Can someone Explain it more clearly ? Explaination in book is :: This cyclic static initialization cannot be reliably detected during…
Prateek
  • 11,146
  • 11
  • 54
  • 77
0
votes
3 answers

using static initialization blocks to improve performance

Given an existing code base being used in production containing a class A that contains a method that populates N fields of another POJO class B using setters and returns the POJO to the caller and given that all instances of class B will be…
CKing
  • 14,153
  • 4
  • 39
  • 77
-1
votes
2 answers

How to mitigate user-facing API Effect of shared members in templated classes?

Let's say I have a type of lookup table which I can build for a given integer: class FooLookupTable { ... public: FooLookupTable(int radix) { ... } }; Then there's a class whose template parameter is that same integer, and…
-1
votes
1 answer

Do static members of a class get initialized even before static constructor gets called?

I was reading MSDN Documentation and there seems to be a contradiction. Static members are initialized before the static member is accessed for the first time and before the static constructor, if there is one, is called. also in the next…
SamuraiJack
  • 4,160
  • 11
  • 60
  • 152
-1
votes
2 answers

static map not intialized correctly?

I'm using some c++ code in a static library in a macOS App. The c++ code contains the following: static map aMap1; __attribute__((constructor)) static void initialize() { { static map aMap2; printf("map1: %d,…
Nick
  • 3,464
  • 2
  • 25
  • 42
-1
votes
1 answer

static initializer block return void

I know that it isnt about my problem but just to you know, this is my first stackoverflow post and yes, my english isnt quite good so please, i sincerely ask you guys, be patience. I'd chosen english community because brazillian stack overflow…
-1
votes
3 answers

What is true reason for initiliazing need of final varibles before use

I know that: A blank final class variable must be definitely assigned by a static initializer of the class in which it is declared, or a compile-time error occurs. A blank final instance variable must be definitely assigned at the end of…
1 2 3
19
20