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

Reducing operations challange problem.

I'm trying to solve this challange, and getting error "Non-static method cannot be referenced from a static context" at (String::length).

public static Optional<HousingRecord> getHighestValueIndexHousingRecordDeclaratively(List<HousingRecord> records) { // TODO: Create a stream off of the records // TODO: Find and return the maximum using a Comparator that compares the current home value index return records.stream() .map(HousingRecord::getCurrentHomeValueIndex) .max(Comparator.comparingInt(String::length)); }

1 Answer

Steven Parker
Steven Parker
231,271 Points

Perhaps comparing the length of numbers is not the best way to determine which is larger. Try skipping the "map" and just getting the max by comparing the values directly.