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
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()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.