I want to check if a Java class contains a default constructor.
Case 1 :
public class ClassWithConstructor {
//attributes...
//default constructor
public ClassWithConstructor(){}
}
Case 2 :
public class ClassWithoutConstructor {
//attributes...
// no default constructor
}
In case 1 , I want to print "ClassWithConstructor contains a default constructor."
In case 2, I want to print "ClassWithoutConstructor doesn't contain any default constructor".
You can inspect your class via the Java Reflection API, there is a class called Constructor (see http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/package-frame.html). Not sure, though, whether you can actually distinguish the Java default constructor and a parameterless one you defined on your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With