Skip to content
Ondrej Kucera edited this page Dec 5, 2017 · 13 revisions
  • interface private methods - you can write helpers for more classes, but they won't be public
interface Util {
  default int getNumber() { return helper(); }
  private int helper() { return 4; }
}
  • effectively final in try-with-resources => use AutoCloseable for a class that is used in try-catch when we leave the scope on try-catch. Then the close method is automatically called. (can be dangerous!)
class Resource implements AutoCloseable {
  public void foo() { ... };
  public void close() { ... };
}

public static Sample {
  Resource resource = new Resource();
  try(resource) {
    resource.method();
}