defunkt (owner)

Revisions

gist: 215826 Download_button fork
public
Public Clone URL: git://gist.github.com/215826.git
Embed All Files: show embed
Java #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Animal: class {
  name: String
  age := 0
 
  /** Simple constructor with a member-assign-argument */
  init: func (=name) {}
  // equivalent to
  // init: func (name: String) { this name = name }
 
  /** Another constructor, we need to choose a suffix, here 'withAge' */
  init: func ~withAge (.name, =age) {
    this(name) // call another constructor
  }
  // equivalent to
  // init: func (name: String, age: Int) { this(name); this age = age }
 
  /** An abstract function, should be implemented by child classes */
  shout: abstract func
  // note: if we have no arguments, we don't need parenthesis
  // (heh, that's what the 'func' keyword is for!)
}
 
Dog: class extends Animal {
 
  shout: func {
    "Woof, woof!" println()
  }
}