Skip to content

Instantly share code, notes, and snippets.

@nbness2
Last active December 22, 2021 09:16
Show Gist options
  • Save nbness2/73252716473cd861e9f6635de6a7e6fa to your computer and use it in GitHub Desktop.
Save nbness2/73252716473cd861e9f6635de6a7e6fa to your computer and use it in GitHub Desktop.
Java lambda example
public record AnimalImpl(String name, String noise) implements Animal {
@Override public String getName() { return this.name; }
@Override public String getNoise() { return this.noise;}
}
public static <T> void also(T thing, Consumer<T> block) {
final T finalThing = thing;
block.accept(finalThing);
}
public static void main(String[] args) {
var roofus = new AnimalImpl("Roofus", "woof");
also(roofus, woofer -> System.out.println(woofer.makeNoise()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment