Skip to content

Instantly share code, notes, and snippets.

@nowshad-hasan
Created October 9, 2021 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nowshad-hasan/0fc5e5b58c92cfe5a3ca29f18e4ef1f9 to your computer and use it in GitHub Desktop.
Save nowshad-hasan/0fc5e5b58c92cfe5a3ca29f18e4ef1f9 to your computer and use it in GitHub Desktop.
void checkLocalInterface() {
interface Runner {
void run();
}
Runner runner = () -> System.out.println("Running");
runner.run();
}
void checkLocalEnum() {
enum COLOR {RED, PURPLE, BLUE}
System.out.println(Arrays.toString(COLOR.values()));
}
/*
Local enum is implicitly static. So, we can't work with non-static variable in local enum.
*/
void checkLocalEnum2() {
int val = 2;
enum LEVEL {
LOW, MID, HIGH;
void getValue() {
System.out.println(this);
// System.out.println(val); // ERROR, non-static variable can't be referenced from static context.
}
}
for (LEVEL level : LEVEL.values()) {
level.getValue();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment