Yes, with a qualification: they are instances of object subtypes, but do not necessarily possess a unique identity. A lambda expression is an instance of a functional interface, which is itself a subtype of Object
. To see this, consider the legal assignments:
Runnable r = () -> {}; // creates a lambda expression and assigns a reference to this lambda to r
Object o = r; // ordinary widening conversion
To understand the situation, it is useful to know that there are both short-term goals and a longer-term perspective for the implementation in Java 8. The short-term goals are to support internal iteration of collections, in the interests of efficiently utilising increasingly parallel hardware. The longer-term perspective is to steer Java in a direction that supports a more functional style of programming. Only the short-term goals are being pursued at present, but the designers are being careful to avoid compromising the future of functional programming in Java, which might in the future include fully-fledged function types such as are found in languages such as Haskell and Scala.
The question of whether lambdas are objects must be answered on the basis of how they fit into the Java’s type system, not on how they happen to be implemented at any moment. Their status as objects, which stems from the fundamental decision to make them instances of interfaces, has both positive and negative aspects:
- it enables lambda expressions to fit into the existing type system with relatively little disturbance;
- lambda expressions inherit the methods of
Object
.
But note that because lambdas do not necessarily possess a unique identity, the equals
method inherited from Object
has no consistent semantics.
Here you run into the problem that a lambda expression in isolation is nothing yet.
() -> {} // not an object
Runnable r = () -> {} // Ok, r refers to an object
So, it doesnt make a lot of sense to say that a lambda expression “is” an object.
This is the same point as in the comment on this page. And yes, lambda expressions may not be legal Java expressions in isolation. But why should that mean that we don’t reason about their properties when they do occur in context and are legal Java expressions?