Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 18, 2015 15:18
Show Gist options
  • Select an option

  • Save shigemk2/dc303f84aac4680e3bef to your computer and use it in GitHub Desktop.

Select an option

Save shigemk2/dc303f84aac4680e3bef to your computer and use it in GitHub Desktop.
class TestInt extends Test {
private int i;
public TestInt(int i) { this.i = i; }
public String foo() {
if (i == 1) return "bar";
return super.foo();
}
}
class TestStr extends Test {
private String s;
public TestStr(String s) { this.s = s; }
public String foo() {
if (s.equals("1")) return "baz";
return super.foo();
}
}
abstract class Test {
public String foo() { return "?"; }
public static void main(String[] args) {
System.out.println(new TestInt( 0 ).foo());
System.out.println(new TestInt( 1 ).foo());
System.out.println(new TestStr("0").foo());
System.out.println(new TestStr("1").foo());
}
}
class TestInt(i :Int) extends Test {
override def foo(): String = {
if (i == 1) return "bar"
super.foo()
}
}
class TestStr(s :String) extends Test {
override def foo(): String = {
if (s.equals("1")) return "baz"
super.foo()
}
}
class Test {
def foo() = "?"
}
object Test {
def main(args: Array[String]) {
println(new TestInt( 0 ).foo());
println(new TestInt( 1 ).foo());
println(new TestStr("0").foo());
println(new TestStr("1").foo());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment