Skip to content

Instantly share code, notes, and snippets.

@vaskoz
Created August 14, 2013 04:14
Show Gist options
  • Save vaskoz/6227954 to your computer and use it in GitHub Desktop.
Save vaskoz/6227954 to your computer and use it in GitHub Desktop.
Java 8 Method Reference examples from JLS 8
System::getProperty
String::length
List<String>::size // explicit class type args
List::size // inferred class type args, or generic
int[]::clone
T::tvarMember
"abc"::length
foo[x]::bar
(test ? list.map(String::length) : Collections.emptyList())::iterator
super::toString
String::valueOf // overload resolution needed
Arrays::sort // type args (if any) inferred from context
Arrays::<String>sort // explicit type args
ArrayList<String>::new // constructor for parameterized type
ArrayList::new // inferred class type args, or generic
Foo::<Integer>new // explicit generic constructor type arguments
Bar<String>::<Integer>new // generic class, generic constructor
Outer.Inner::new // inner class constructor
int[]::new // array "constructor"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment