Skip to content

Instantly share code, notes, and snippets.

@dsteiner93
dsteiner93 / 1-DefExample.java
Last active January 11, 2018 11:43
@def proposal
import lombok.Def;
import java.util.Optional;
import com.google.common.collect.ImmutableMap;
public class DefExample {
public static void main(String[] args) {
System.out.println("All defaults:");
foo(1, 2);
System.out.println();
@dsteiner93
dsteiner93 / 1-Overview.md
Last active June 23, 2021 18:42
Default method parameters in Java

Java does not offer default method parameters like many languages do. While there are some inelegant workarounds ([see this stack overflow thread for details][stack]) design patterns are no substitute for the simplicity of Python (and most other languages') default parameter syntax:

def method(a, b, c=1, d=1):
  return a+b+c+(2*d)

method(1, 1) # Returns 5
method(1, 1, d=2) # Returns 7