A static block is a normal block of code enclosed in braces, { }, and preceded by the static keyword.
Questions tagged [static-block]
166 questions
2
votes
1 answer
2
votes
0 answers
Is there any difference using inner-loop in static block and assigning pairs ? Compared with directly assigning values in static block
For Instance
case:1) Using inner-loop static block and assigning values, as below:
public class MyClass
{
public static final Map CARD_TYPES;
static
{
CARD_TYPES = new HashMap()
{
{
…

Sunil
- 71
- 1
- 11
2
votes
3 answers
Pass a constructor argument to a static block
I have a class like this
public class CustomRestClient {
private static String dbString;
public CustomRestClient(String db) {
this.dbString = db;
}
static {
try {
Client.setServer(Client.Server.LOCAL);
…

Roshan Upreti
- 1,782
- 3
- 21
- 34
2
votes
2 answers
What is happening with more than one static block in Java byte-code?
Here’s a very basic application in Java, containing only one class. In that class, there is one main method and two static blocks.
class Test {
public static void main(String args[]) {
System.out.println("Main");
}
static {
…
user6731783
2
votes
2 answers
Static Block not running, no final variables
I have this code here using my API:
package org.midnightas.os.game.dots;
import java.awt.Graphics2D;
import org.midnightas.os2.Key;
import org.midnightas.os2.MidnightasOS;
import org.midnightas.os2.gameapi.Game;
public class Dots extends Game…

mid
- 421
- 5
- 20
2
votes
1 answer
Question about singleton property
I'm reading the java tutorial for enums located here and have a question: http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html#Card
The part i'm confused about is as follows:
"The Card class, above, contains a
static factory that…

Jack
- 83
- 2
2
votes
1 answer
Magento 1.8.1 how to display layered navigation in a static block like the catergory left navigation?
I would like to display the layered navigation (as per the category left navigation) within a static block without modifying local.xml.
The intention is to convert parent categories into cms pages displaying the layered navigation of its…

Fab
- 278
- 4
- 17
2
votes
2 answers
Advantages of multiple static blocks
class A{
static{
//initialize all things here
}
}
This is the way I use static blocks in my code. But as we can also keep multiple static blocks in a class
class A{
static{
//do something here
}
static{
//do…

Narendra Pathai
- 41,187
- 18
- 82
- 120
2
votes
1 answer
How to get the base url of a specific store view in a static block?
I know that in a .phtml file you do it like this for example:
helper('derco_core')->getStoreUrl('dcmotosesp')?>
I want to do the same thing inside a static block. Thanks in advance.

Jonathan Calb
- 731
- 1
- 10
- 28
2
votes
1 answer
Get Custom attribute from current product in product tabs - Magento
I would like to get some custom attributes from the current product in the product tabs (on product page). At the moment, the tabs are populated from cms > static blocks. Is it possible to get the value of those custom product attributes in the…
user1705923
2
votes
1 answer
Magento category static block only not working
If I set a category to products only, it shows products only.
if I set it to static block and products, it shows the static block and products.
If I set it to static block only, it shows static block and products.
That last one doesn't seem right to…

Benubird
- 18,551
- 27
- 90
- 141
2
votes
3 answers
Magento - programmatically save static block content
I have a static block that I would like updating by a script which gets run via cron.
I've found out how to create or retrieve a block programmatically, but not how to edit an existing one.
This works to retrieve a block:
// Retrieve the layout…

jsims281
- 2,206
- 2
- 30
- 57
1
vote
1 answer
Can't access static methods from outside until JavaScript's static block is over?
class B {
foo() {
return A.foo(); // message: Uncaught ReferenceError: A is not defined
}
}
class A {
static {
console.log(new B().foo());
}
static foo() {
return "foo";
}
}
I expected the "foo" to…

서다운
- 25
- 2
1
vote
0 answers
Java - Static method called by superclass always return null
I have MySubClass that extends MySuperClass. In MySuperClass I call the method MySubClass.getMap() from a static block in MySuperClass but it alway returns null.
I really don't get why because in the same static block in MySuperClass I call…

Korenji
- 19
- 4
1
vote
0 answers
Accessing static variable from new thread inside static block causing program freeze
It seems that "static block + new thread + static variable" would cause program freeze?
public class HelloWorld{
private static String str = "Hi";
static{
Thread thread = new Thread(new Runnable(){
public void…

charlie lin
- 107
- 1
- 1
- 5