Method Class | isDefault() Method in Java Last Updated : 05 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The java.lang.reflect.Method.isDefault() method is used to check whether the method of the Method object is a Default Method: or not. It returns true if method object is a default method, otherwise it will return false. Default Method: A public non-abstract on-static method with a body declared in an interface type. Syntax: public boolean isDefault() Return Value: This method returns a boolean value. It returns true if method object is a default method by JVM Specifications, else false. Below program illustrates isDefault() method of Method class: Example 1: Java /* * Program Demonstrate isDefault() method * of Method Class. */ import java.lang.reflect.Method; public class GFG { // create main method public static void main(String args[]) { try { // create class object for interface Shape Class c = Shape.class; // get list of Method object Method[] methods = c.getMethods(); // print Default Methods for (Method m : methods) { // check whether the method is Default Method or not if (m.isDefault()) // Print System.out.println("Method: " + m.getName() + " is Default Method"); } } catch (Exception e) { e.printStackTrace(); } } private interface Shape { default int draw() { return 0; } void paint(); } } Output: Method: draw is Default Method Example 2: Java /* * Program Demonstrate isDefault() method * of Method Class. * This program checks all default method in Comparator interface */ import java.lang.reflect.Method; import java.util.Comparator; public class Main6 { // create main method public static void main(String args[]) { try { // create class object for Interface Comparator Class c = Comparator.class; // get list of Method object Method[] methods = c.getMethods(); System.out.println("Default Methods of Comparator Interface"); for (Method method : methods) { // check whether method is Default Method or not if (method.isDefault()) // print Method name System.out.println(method.getName()); } } catch (Exception e) { e.printStackTrace(); } } } Output: Default Methods of Comparator Interface reversed thenComparing thenComparing thenComparing thenComparingInt thenComparingLong thenComparingDouble Reference: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#isDefault-- Comment More infoAdvertise with us Next Article Method Class | isDefault() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-lang package Java-Functions Java-Method Class java-lang-reflect-package +1 More Practice Tags : Java Similar Reads Method Class | isBridge() Method in Java The java.lang.reflect.Method.isBridge() method is used to check whether a function is a Bridge Function or not. This method returns true if method object is a bridge method otherwise it returns false. Bridge Method: These are methods that create an intermediate layer between the source and the targe 3 min read Method class isSynthetic() method in Java java.lang.reflectMethod class help us to get information of a single method on a class or interface. This class also provides access to the methods of classes and invoke them at runtime. isSynthetic() method of Method class: This function checks whether Method Object is a synthetic construct or not. 3 min read Method Class | isVarArgs() Method in Java The java.lang.reflect.Method.isVarArgs() method of Method class checks whether Method Object was declared to take a variable number of arguments or not. If the method can take a variable number of arguments then returns true otherwise it will return false. VarArgs(variable-length arguments): VarArgs 3 min read Method Class | getDefaultValue() Method in Java The getDefaultValue() method of java.lang.reflect.Method class. It returns the default value for the annotation member represented by the Method object. When annotation member belongs to primitive types, then the method returns the instance of that wrapper type. It returns null if annotation member 3 min read Method Class | equals() Method in Java The java.lang.reflect.Method.equals(Object obj) method of Method class compares this Method Object against the specified object as parameter to equal(object obj) method. This method returns true if the Method object is the same as the passed object. Two Methods are the same if they were declared by 3 min read Like