Skip to content

Instantly share code, notes, and snippets.

@SeongUgJung
Last active September 4, 2016 03:43
Show Gist options
  • Save SeongUgJung/73f06d245d8ddcf1c62e26116fcbe207 to your computer and use it in GitHub Desktop.
Save SeongUgJung/73f06d245d8ddcf1c62e26116fcbe207 to your computer and use it in GitHub Desktop.
java first citizen class
interface Do {
String do();
}
// possible case
class DoSomething {
String do(Do do) {
// it can be
return do.do();
}
}
// impossible case
class DoSomething2 {
String do(Do do) {
// java cannot be done this
return do.do() = () -> {
String ret = super.do();
return "Impossible case : " + ret;
}
}
}
class DoSomething3 {
String do(Do do) {
return do.do2() = () -> {
String ret = do.do();
return "Impossible case2 : " + ret;
}
}
}
class Main {
public static void main(String[] args) {
String value1 = new DoSomething.do(() -> "Hello World"); // value1 = Hello World
String value2 = new DoSonething2.do(() -> "Hello World2"); // expect value2 = Impossible case : Hello World2, but it cannot be
String value3 = new DoSonething3.do(() -> "Hello World3"); // expect value3 = Impossible case2 : Hello World3, but it cannot be
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment