Quick revision
The short answer
A method reference is a short way to write a lambda that only calls one existing method, and there are four kinds. A static reference, Integer::parseInt, means s -> Integer.parseInt(s). A bound instance reference, System.out::println, calls the method on a receiver fixed when the reference is created. An unbound instance reference, String::length, takes the receiver as the first argument, s -> s.length(). A constructor reference, ArrayList::new, means () -> new ArrayList<>() or a constructor with arguments, depending on the target type, and int[]::new is the array form, an IntFunction<int[]>.
What to remember
In this answer, we saw the four kinds of method reference and the lambda each one stands for. A static reference such as Integer::parseInt passes the arguments to a static method. A bound reference such as System.out::println calls a method on a receiver evaluated once, when the reference is created. An unbound reference such as String::length uses the first argument as the receiver. A constructor reference such as ArrayList::new calls the constructor that fits the target type, and int[]::new creates arrays from a length. When a class has both a fitting static and instance method, as with Integer::toString, the reference is ambiguous and a lambda is clearer.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A method reference is a short way to write a lambda that only calls one existing method, and there are four kinds. A static reference, Integer::parseInt, means s -> Integer.parseInt(s). A bound instance reference, System.out::println, calls the method on a receiver fixed when the reference is created. An unbound instance reference, String::length, takes the receiver as the first argument, s -> s.length(). A constructor reference, ArrayList::new, means () -> new ArrayList<>() or a constructor with arguments, depending on the target type, and int[]::new is the array form, an IntFunction<int[]>.
Why this question is asked
Method references make stream code read almost like English: map(String::trim), filter(Objects::nonNull), collect(toCollection(TreeSet::new)). But the double colon hides four different rules about where the arguments go, and mixing them up leads to confusing compile errors or, with bound references, surprising behaviour at run time. Interviewers ask this question to check that we can say exactly what lambda each reference stands for. In this answer, we will recap what a method reference is, go through each of the four kinds with code and the equivalent lambda, look at the array constructor form, and finish with how the compiler chooses between kinds and where that becomes ambiguous.
1A Quick Recap of Method References
A lambda often does nothing but call one method with its own arguments: s -> s.length(), or x -> System.out.println(x). A method reference names that method directly instead of writing the lambda. Like a lambda, it has no type of its own; it takes its type from the target functional interface, and the compiler checks that the method fits that interface's method.
The part before the double colon tells the compiler where to find the method, and that is what decides the kind: a class name for a static method or for an unbound instance method, an expression for a bound instance method, and a class name with new for a constructor.
2Static Method References
A static reference names a static method of a class. The arguments of the functional interface's method become the arguments of the static method, in order.
3Bound Instance Method References
A bound reference names an instance method on a specific object, written as an expression before the double colon. The receiver is bound, that is, evaluated and fixed when the reference is created, and all the interface method's arguments go to the method.
Notice the word now in the first comment. The expression System.out is evaluated once, when printer is created. If a test later calls System.setOut to redirect output, printer still writes to the old stream, while the lambda x -> System.out.println(x) would read System.out again on every call. The same early evaluation is why a bound reference on a null expression throws NullPointerException immediately, at the line that creates it.
4Unbound Instance Method References
An unbound reference names an instance method through the class, with no particular object. The receiver is supplied later: the first argument of the interface method becomes the object the method is called on, and any remaining arguments are passed to it.
This is the kind that most often confuses people, because String::length looks like a static call, but length() has no parameters. The compiler resolves it by treating the first argument as the receiver. That is why Comparator<String>, whose method takes two strings, can be built from compareToIgnoreCase, which takes one: the first string is the receiver and the second is the argument.
5Constructor and Array Constructor References
A constructor reference, ClassName::new, creates a new object. Which constructor it calls depends on the target type's method: a Supplier picks the no-argument constructor, a Function picks a one-argument constructor whose parameter fits, and so on. Arrays have their own form, Type[]::new, which takes the length as an int.
| Kind | Example | Equivalent lambda | Receiver |
|---|---|---|---|
| Static | Integer::parseInt | s -> Integer.parseInt(s) | none |
| Bound instance | System.out::println | x -> System.out.println(x) | fixed when created |
| Unbound instance | String::length | s -> s.length() | the first argument |
| Constructor | ArrayList::new | () -> new ArrayList<>() | a new object |
| Array constructor | int[]::new | n -> new int[n] | a new array |
The array form is common in Stream.toArray, which takes an IntFunction<A[]> so the stream can create an array of exactly the right type and length, instead of returning Object[].
6How the Compiler Chooses, and When It Cannot
For ClassName::method, the compiler searches for a static method that fits the target's parameters, and for an instance method that fits when the first parameter is used as the receiver. If exactly one search succeeds, that is the kind. If both succeed, the reference is ambiguous and does not compile. The classic example is Integer::toString.
When this happens, we pick a different method, or write the lambda. Clarity is the reason method references exist; when a reference makes the reader stop and work out which method is meant, the lambda is the better choice.
7Follow-up questions
What are this::method and super::method?
They are bound references whose receiver is the current object. this::render is equivalent to x -> this.render(x), and super::render calls the superclass's version of the method on the current object. Both capture this, so they keep the enclosing object alive as long as the reference lives.
Is a method reference faster than a lambda?
No measurable difference in practice. Both compile to invokedynamic with LambdaMetafactory. A method reference may avoid one synthetic method, but the JIT inlines small calls either way. Choose by readability.
Why does Comparator.comparing(Person::name) work?
comparing takes a Function<T, U> key extractor, and Person::name is an unbound reference, p -> p.name(), so the comparator calls it on each of the two persons and compares the results. Unbound references are the most common kind in comparators and stream maps.
8Conclusion
In this answer, we saw the four kinds of method reference and the lambda each one stands for. A static reference such as Integer::parseInt passes the arguments to a static method. A bound reference such as System.out::println calls a method on a receiver evaluated once, when the reference is created. An unbound reference such as String::length uses the first argument as the receiver. A constructor reference such as ArrayList::new calls the constructor that fits the target type, and int[]::new creates arrays from a length. When a class has both a fitting static and instance method, as with Integer::toString, the reference is ambiguous and a lambda is clearer.
Open with
A method reference is shorthand for a lambda that just calls one existing method, and there are four kinds, depending on what comes before the double colon. A static reference, like Integer::parseInt, passes the interface method's arguments to a static method, so it means s -> Integer.parseInt(s).
Then, if they want more
A bound instance reference has an expression before the colons, like System.out::println: the receiver is evaluated once when the reference is created and then fixed, so it means x -> System.out.println(x) on that particular stream.
That early evaluation matters; if the expression is null you get a NullPointerException right away, and if System.out is later replaced, the reference still uses the old one.
An unbound instance reference names an instance method through the class, like String::length: the first argument becomes the receiver, so it is s -> s.length(), and String::compareToIgnoreCase can be a Comparator because the first string is the receiver and the second the argument.
A constructor reference, like ArrayList::new, picks the constructor that fits the target: a Supplier gives the no-arg constructor and a Function<Integer, List> gives the capacity one. For arrays there is int[]::new, an IntFunction<int[]>, which is what Stream.toArray uses. If both a static and an instance method fit, like Integer::toString, it is ambiguous, and I would write the lambda.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- java.util.stream, package documentation, java.util.function, package documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain the four kinds of method reference with an example of each: static, bound...": https://scrivio-interview-library.netlify.app/java/lambdas/c5c8bcb584/