o9s
is a microblog
home archives search feed blogroll


Baseball Programming Paradigm

In the Baseball Programming Paradigm” only baseballs can return values. All other methods must return void.


public class StringBaseball extends Exception {

  private String stringValue; 

  public StringBaseball(String stringValue) {
    super("");
    this.stringValue = stringValue;
  }

  public String getStringValue() {
    return stringValue;
  }

}

public class Person {
  private String name;

  public void setName(String name) {
    this.name = name;
  }

  public void getName() {
    throw new StringBaseball(name);
  }
}

public class Main() {

  public static void main(String[] args) {
    Person p = new Person();
    p.setName("Billie");

    // Display name.
    try {
      p.getName();
    } catch (StringBaseball sb) {
      System.out.println(sb.getStringValue());
    }
  }

}
Posted on 2018-04-20   #java  






← Next post    ·    Previous post →