static-initializer Questions
9
Solved
My question is about one particular usage of static keyword. It is possible to use static keyword to cover a code block within a class which does not belong to any function. For example following c...
Moccasin asked 2/12, 2008 at 20:27
6
Solved
I've got this warning recently (VC++ 2010)
warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
I'm assuming this is the Critical Section. It's been a w...
Quinate asked 30/6, 2011 at 1:11
10
Solved
So I've been brushing up on my Java skills as of late and have found a few bits of functionality that I didn't know about previously. Static and Instance Initializers are two such techniques.
My q...
Misleading asked 29/4, 2009 at 22:39
8
I saw it suggested on a blog that the following was a reasonable way to do a "reverse-lookup" using the getCode(int) in a Java enum:
public enum Status {
WAITING(0),
READY(1),
SKIPPED(-1),
COM...
Upshot asked 15/3, 2011 at 18:30
3
Solved
I'm trying to initialize a big array of elements with the same initializer. 64 elements is just an example — I want to make it at least 16k. Unfortunately a simple
let array : [AllocatedMemory<...
Tattletale asked 28/3, 2016 at 8:9
8
Solved
Why doesn't Java allow to throw a checked exception from a static initialization block? What was the reason behind this design decision?
Multifoil asked 15/1, 2010 at 8:31
8
Solved
Say a project contains several classes, each of which has a static initializer block. In what order do those blocks run? I know that within a class, such blocks are run in the order they appear in ...
Overscrupulous asked 5/1, 2010 at 17:1
4
Solved
I am trying to initialize a static final variable. However, this variable is initialized in a method which can throw exception, therefor, I need to have inside a try catch block.
Even if I know th...
Ornithorhynchus asked 23/4, 2018 at 9:19
7
Solved
You'll probably ask, why would I want to do that - it's because I'm using a class (from an external library) which does stuff in its static initializer and I need to know whether it's been done or ...
Tuinal asked 9/9, 2010 at 16:33
2
Solved
My understanding of classloading was that a class gets loaded when it is first needed (to put it in a very simple way). Running the following sample with -verbose:class and a modified version of th...
Tubman asked 15/1, 2017 at 0:24
2
Solved
Is it possible to initialize an companion object before the init block in a Kotlin class? If so, how? If not, is there a way to accomplish the same thing.
I have the following scenario,
class A(...
Sexivalent asked 31/10, 2016 at 11:21
3
Quoth JLS #8.1.3:
Inner classes may not declare static initializers (§8.7)......
This is demonstrated as such:
class A {
class B {
static { // Compile-time Error: Cannot define static initi...
Trujillo asked 23/8, 2014 at 5:2
6
Solved
Can someone explain me what the following is?
public class Stuff
{
static
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch ( ClassNotFoundException exception )
{
log.error( "...
Mendoza asked 15/11, 2009 at 10:57
6
Solved
public class Main {
public static final Logger LOGGER = Logger.getLogger(Main.class.getName());
static {
try {
LOGGER.addHandler(new FileHandler("errors.log",true));
}
catch(IOException ex) ...
Nissa asked 12/4, 2011 at 12:29
3
Solved
Can I call a static method from a static initializer in Java? Is the following valid and guaranteed to work as per the Java specification?
public class Foo {
private final static int bar;
priv...
Bakunin asked 13/3, 2016 at 23:20
1
static boolean isClassLoaded(String fullname) {
try {
Class.forName(fullname, false, Loader.instance().getModClassLoader());
return true;
} catch (Exception e) {
return false;
}
}
does this...
Subassembly asked 9/10, 2015 at 14:28
6
Solved
I'm using a static code block to initialize some controllers in a registry I have. My question is therefore, can I guarantee that this static code block will only absolutely be called once when the...
Boarer asked 18/5, 2009 at 16:30
1
I've been through the relevant section of C# Language Spec (v5.0) but I can't find the piece that's relevant to what I'm seeing.
If you have a run of the code below, you'll see the output below, ...
Cornel asked 17/4, 2015 at 23:19
6
Solved
Once a class is loaded is there a way to invoke static initializers again?
public class Foo {
static {
System.out.println("bar");
}
}
Edit:
I need to invoke the static initializer because ...
Sumrall asked 25/3, 2009 at 18:8
2
Solved
I have a class which has fairly complex static initialization. I'm reading files from a directory, then parsing those json files, mapping to objects, and filling up a list. You can imagine, there c...
Muttonchops asked 16/10, 2014 at 7:47
2
Solved
Why isn't it possible to access static final fields from a corresponding static initializer using the declaring class as qualifier (in a static way)?
At first, I thought this was an Eclipse bug:
...
Vassalize asked 13/8, 2014 at 11:16
6
Solved
how to register a java class if the static initializer isn't called till the class is referenced
I've an interface implemented by classes that perform a file processing, say searching or whatever.
public interface FileProcessorInterface {
public void processFile(String fileName);
}
Then ...
Flesher asked 6/8, 2013 at 21:6
7
Solved
I know how a static init block works.
Can anyone please tell me some typical uses of it.
Otey asked 3/2, 2010 at 8:37
1
Solved
I noticed something in static initializers which may be a bug in the javac. I have constructed a scenario where I can assign a variable a value but not read that value back.
The two examples are b...
Rosannrosanna asked 7/5, 2013 at 13:58
6
Solved
What is the best and cleanest way to do this? Specifically, I need some code in a static initializer block to run in that class, but I'd like to make this as clean-looking as possible.
Demmy asked 24/8, 2010 at 19:9
1 Next >
© 2022 - 2025 — McMap. All rights reserved.