Method references don't work with non-static methods AFAIK. I tried using them in the following way
Arrays.stream(new Integer[] {12,321,312}).map(Integer::toString).forEach(System.out::println);
Which resulted in the compilation error as seen in the link.
Problem
While using AssertJ
library, I used something like this,
AbstractObjectAssert<?, Feed> abstractObjectAssertFeed2 = assertThat(feedList.get(2));
abstractObjectAssertFeed2.extracting(Feed::getText).isEqualTo(new Object[] {Constants.WISH+" HappyLife"});
where Feed
is a noun and getText
is a getter method and not static, but it worked fine without compilation error or any error which puzzled me.
Am I missing something about how method references work?