For literate geeks: An original haiku in (valid) Java.
© Marc Weber. All rights reserved.
Notes on implementation:
- The top-level HaikuBuilder class is not public, so it can be saved in a file by a different name (e.g., Haiku.java).
- A Haiku class needs to be defined.
- A Hai class needs to be defined as a subclass of Haiku (so that a Hai reference can be upcast to type Haiku), and Hai must have a constructor that takes a String argument.
- Once an instance of HaikuBuilder is created, its compose method can be called to return a reference to a new instance of Haiku.
Related: main method