Не знаю, может боян, но меня сегодня такая идея посетила :) abstract class Node extends RuntimeException { } class Leaf extends Node { public final String value; public Leaf(String value) { this.value = value; } } class BNode extends Node { public final Node left; public final Node right; public BNode(Node left, Node right) { this.left = left; this.right = right; } } public class Main { public static void walk(Node node, StringBuffer buf) { try { throw node; } catch (Leaf n) { buf.append(n.value); } catch (BNode n) { walk(n.left, buf); walk(n.right, buf); } } public static void main(String[] args) { Node node = new BNode(new Leaf("1"), new BNode(new BNode(new Leaf("2"), new Leaf("3")), new Leaf("4"))); StringBuffer sb = new StringBuffer(); walk(node, sb); System.out.println(sb); } }