zcaudate
zcaudate

Reputation: 14258

how to use reflection to determine whether an Interface has a default method?

I'm like to figure out which methods in an Interface has a default method.

For example, in java.util.Collection, stream() has a default method. How would one go about programmatically finding that out

Upvotes: 0

Views: 49

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198033

You can get all the methods from an interface from its Class<?>.getMethods(): myInterface.getMethods().

Each of those Method objects has a function isDefault(): thisMethod.isDefault().

Upvotes: 4

Related Questions