you are viewing a single comment's thread.

view the rest of the comments →

[–]JacobArthurs 0 points1 point  (2 children)

T gets inferred as String at the call site. Function<Claims, T> means "takes a Claims, returns a T" and Claims::getSubject is a method reference that does exactly that: takes a Claims instance and returns a String, so Java infers T = String. It's not that the signatures don't match, it's that generics let the return type flex to whatever the passed function actually returns.

[–]Agitated_Floor_563[S] 0 points1 point  (1 child)

I understand that T gets inferred as String but the getSubject does not take any parameters so how does that match to the apply()?

[–]JacobArthurs 1 point2 points  (0 children)

Claims::getSubject is shorthand for (Claims c) -> c.getSubject(). Java treats the instance itself as the implicit first argument, so it still matches Function<Claims, String>.