java/ch/wlkl/javaExamples/ExBlock.java
package ch.wlkl.javaExamples;
/*
* Block.java
*
* Created on 13. Dezember 2003, 12:30
*/
/**
*
* @author walter
*/
interface ExBlockInt {
void doit();
}
class ExBlock implements ExBlockInt {
final static boolean staticSay = true;
static {
if (staticSay) {
System.out.println("static block 1 frame " + Java.thisFrame());
Java.thisMethod();
}
}
{
if (staticSay)
System.out.println("anonymous (initialiser) block 2 this " + this
+ " frame " + Java.thisFrame());
}
static {
if (staticSay)
System.out.println("static block 3 frame " + Java.thisFrame());
}
{
if (staticSay)
System.out.println("anonymous (initialiser) block 4 this " + this
+ " frame " + Java.thisFrame());
}
String txt;
ExBlockInt[] blocks = new ExBlockInt[33];
/** Creates a new instance of Block */
public ExBlock(String txt) {
this.txt = txt;
}
public void sh(String txt) {
System.out.println(txt + " from exBlock[" + this.txt + "].sh ");
}
public void doit() {
sh("Block.doit");
};
public void blocks(final String arg) {
ExBlockInt b3[] = { new ExBlockInt() {
public void doit() {
sh("do[null] ExBlockInt");
}
}, new ExBlock("b0/" + arg), new ExBlock("b1/" + arg) {
public void doit() {
ExBlock.this.sh("do[zwei]");
}
}, new ExBlock("b2/" + arg) {
public void doit() {
sh("do[drei]");
}
}, new ExBlock("b3/" + arg) {
public void doit() {
sh("do[vier]");
}
} };
sh("====== test b3");
for (int i = 0; i < b3.length; i++)
b3[i].doit();
int ix;
for (ix = 0; blocks[ix] != null; ix++)
;
for (int i = 0; i < b3.length; i++)
blocks[i + ix] = b3[i];
sh("====== test blocks");
txt = txt + "Zwei";
for (int i = 0; blocks[i] != null; i++)
blocks[i].doit();
};
public static void main(String[] args) {
ExBlock inst = new ExBlock("inst");
new Java(args, new String[] { "blocks", "aaa", "blocks", "bbb" })
.invokeMethods(inst);
}
}