theclapp

Search theclapp.blog-city.com

 

Chapter 4, ex 18

posted Wednesday, 15-Jan-2003
20:54 -- Starting 4.18, Java version
20:57 -- Done
---
// ch04_ex18.java

class ch04_ex18 {
String string1;
{
string1 = "init in instance init area";
}

void demo_init() {
System.out.println( "string1: " + string1 );
}

public static void main(String[] args) {
ch04_ex18 obj = new ch04_ex18();
obj.demo_init();
}
}
---

Bruce says, "Describe a use for this feature (other than the one specified in this book [i.e. to support the initialization of anonymous inner classes])." I must admit, I can't see a use for this facility (yet :). It seems to me that everything you could do in the non-static instance initialization, you could do in a constructor. I suppose having a non-static instance initialization sequence allows you to put common constructor code in a single place -- but you could put it in a normal method which you just call from the constructor, too. *shrug* I dunno.

This exercise doesn't really apply to Common Lisp/CLOS.

links: digg this    del.icio.us    technorati    reddit