Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Adding one plus one in idiomatic java.

Name: Anonymous 2010-04-10 4:50


abstract class Number{
   private Integer m_number;
   Number(Integer m_number){
      this.m_number=m_number;
   }
   public Integer getInteger(){
      return m_number;
   }
   Number add(Number a,Number b){
     return new Number(new Integer(a.getInteger().intValue()+
                                   b.getInteger().intValue()));
   }
   String toString(){
       return getInteger().toString();
   }
}
class One extends Number{
  static Number cached_one=new Number(Integer.parseInt(BigInteger.ONE.toString())); //cached for efficiency  
  static Number createNumberOne(){
     return cached_one;
  }
}
class Main{
   public static void main(String[] args){
     Number result=One.createNumberOne().add(One.createNumberOne());
     System.out.println(result);  //result.toString() is invoked here
   }
}

Name: Anonymous 2010-04-10 15:45

>>11
Someone mentioned Jot recently: http://esolangs.org/wiki/Jot

I guess it's normally ASCII source coded so it wouldn't really qualify but there are no invalid sequences of syntactically meaningful characters. You could also treat other characters as comments (as is common in Brainfuck) or just use binary source coding to achieve the desired effect.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List