Skip to content

Instantly share code, notes, and snippets.

@ceki
Created June 19, 2022 12:21
Show Gist options
  • Select an option

  • Save ceki/4bf89b14e688a10a1165dd619c9c5b16 to your computer and use it in GitHub Desktop.

Select an option

Save ceki/4bf89b14e688a10a1165dd619c9c5b16 to your computer and use it in GitHub Desktop.
Overloading of lambdas
package org.slf4j.skunk;
import java.util.function.Supplier;
public class API {
public static void main(String[] args) {
API api = new API();
Integer i0 = 0;
Integer i1 = 1;
Supplier supplier0 = () -> i0;
Supplier supplier1 = () -> i1;
api.anArg(i0);
api.anArg(supplier0);
api.manyArgs(i0, i1);
api.manyArgs(supplier0, supplier0);
api.manyArgs(i0, supplier0);
}
void anArg(Object arg) {
System.out.println("anArg(Object) called");
}
void anArg(Supplier arg) {
System.out.println("anArg(Supplier) called");
}
void manyArgs(Object... arg) {
System.out.println("manyArgs(Object...) called");
}
void manyArgs(Supplier... arg) {
System.out.println("manyArgs(Supplier...) called");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment