mercredi 7 janvier 2015

Getting two constructor when already have no-argument constructor


public class Base {

private Base instance;

private Base() {
}

public static class BaseHelper {
Base instance = new Base();
}
}


In above example I have one no-argument constructor in base class. Now I'm listing the constructors of this class like this:



Constructor<?>[] constructors = Base.class.getDeclaredConstructors();
System.out.println(constructors);


When running this code I get the following output:



[private com.Base(), com.Base(com.Base)]


This tells me that there are two constructors:



  • a private constructor that I have declared

  • a public default constructor


Why is this?






Aucun commentaire:

Enregistrer un commentaire