Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Sneak Peak: Method References

Lewis Cowles
Lewis Cowles
74,902 Points

Are the method references basically passing callable's?

Looking at method references,

Is this simply passing a callable reference?
Will it work with anything implementing callable?
Do you have any cooler examples of this working?

From Linked Oracle docs

Kinds of Method References
There are four kinds of method references:

Kind   Example
Reference to a static method   ContainingClass::staticMethodName
Reference to an instance method of a particular object   containingObject::instanceMethodName
Reference to an instance method of an arbitrary object of a particular type   ContainingType::methodName
Reference to a constructor   ClassName::new

1 Answer

Based off of the documentation I do not see a method call here using a callable as an argument. I see a static method, instance method, and a constructor call.

Lewis Cowles
Lewis Cowles
74,902 Points

Thx buddy, I got that, but it seems just rational to have it callable, and was wondering if the docs are just poorly written / worded as it seems they support at least 4 signatures if not, so they could just use callable, devs get more freedom, and everything else is contracted to the interface.