Created
October 13, 2015 19:23
-
-
Save jakecoffman/9ca198cfd0a4fb68039c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Main | |
IElement element = getElement() | |
printer(element) | |
// Classes | |
IElement getElement() { | |
// simulate not knowing the type of element at runtime | |
if (new Random().nextInt() % 2 == 0) { | |
return new Element1(var1: "hello") | |
} else { | |
return new Element2(var2: "world") | |
} | |
} | |
def printer(Element1 e1) { | |
println e1.var1 | |
} | |
def printer(Element2 e2) { | |
println e2.var2 | |
} | |
interface IElement { | |
} | |
class Element1 implements IElement { | |
String var1 | |
} | |
class Element2 implements IElement { | |
String var2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment