Skip to content

Instantly share code, notes, and snippets.

@lgiudice
Created May 9, 2015 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgiudice/cd5981b38f04c979f5ee to your computer and use it in GitHub Desktop.
Save lgiudice/cd5981b38f04c979f5ee to your computer and use it in GitHub Desktop.
proving that, given an object, we can know if some of the methods it understands are from a trait
public interface InterfaceA {
public default String m1() {
return " This is InterfaceA.m1";
}
}
public class SomeClass implements InterfaceA {
public static void main(String[] args) {
List<Method> declaredMethods = Arrays.asList(new SomeClass().getClass().getMethods());
declaredMethods.forEach(m -> System.out.println(m.getName() + (m.isDefault() ? " is default" : " is not default")));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment