Is there any sense to declare default constructor in Java?
class MyClass {
public MyClass(){}
public MyClass( T someArgs){
//somecode
}
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, when you have other constructors.
It is required when you want to
create object without passing any
parameters to constructor.
In most cases it is required for
reflection, especially when you work
with certain reflection-based
frameworks and libraries (e.g. serialization, Hibernate, Hessian).
Using setters instead generally may
give you better control. It also
works well with inheritance (where
you’d need to explicitly call the
constructor for all specialized
classes, as constructors are not
virtual.