theclapp

Search theclapp.blog-city.com

 

Chapter 4, ex 17

posted Wednesday, 15-Jan-2003
20:32 -- Starting 4.17, Java version
20:40 -- done
---
// ch04_ex17.java

class ch04_ex17 {
static String string1 = "init at def";
static String string2;
static {
string2 = "init in static block";
}

static void demo_inits() {
System.out.println( "string1: " + string1 );
System.out.println( "string2: " + string2 );
}

public static void main(String[] args) {
demo_inits();
}
}
---

20:41 -- Starting 4.17, Lisp version
20:52 -- Done

---
;;;; chapter 4, ex 17
(defclass ch04-ex17 ()
((string1 :initform "init at def"
:allocation :class)
(string2 :initform "init at def, too"
:allocation :class)))
(let ((obj (make-instance 'ch04-ex17)))
(format t "string1: ~a~%string2: ~a~%"
(slot-value obj 'string1)
(slot-value obj 'string2)))
---
CLOS doesn't have a "static block" area for initializations, so I punted on this one.

links: digg this    del.icio.us    technorati    reddit