Which methods are being used as an abstract method for functional interface?
Looking under the java built in interface,
Comparator<T>
functional interface has 2 non default methods, int compare(T o1, T o2)
and boolean equals(Object obj)
. My question is asking the reason of why the latter method does not need to be implemented when using lambda/anonymous, what determines which method is being used as the functional method within the interface.
As of what I understand, functional interface may only take one abstract method to be implemented, but how does it know which method is needed to be implemented during an anonymous class/lambda calls?
My logic is that Comparator takes generic T
, so that it find the following abstract method that uses T
as the parameters, such as int compare(T o1, T o2)
. OR in another case, because of the order of method declaration.4 Replies
⌛
This post has been reserved for your question.
Hey @circle! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
equals
is defined in Object
Oh my bad, that makes sense. 😂
Post Closed
This post has been closed by <@389034898666553344>.