Skip to content

Instantly share code, notes, and snippets.

@kalharbi
Last active May 3, 2023 15:44
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 kalharbi/63de1fd5639b96e064b199e0e16460dd to your computer and use it in GitHub Desktop.
Save kalharbi/63de1fd5639b96e064b199e0e16460dd to your computer and use it in GitHub Desktop.
what seems to be a bug in getDeclaredConstructors(). Will check back later.
public class OuterClass
{
private int x;
private OuterClass(int x){
this.x =x;
}
public static void main( String[] args )
{
// Should print 1 constructor not 2
System.out.println(OuterClass.class.getDeclaredConstructors().length); // prints 2
}
public static class NestedClass{
private int x =0;
public NestedClass(int x){}
// This is not a constructor. Yet, App.class.getDeclaredConstructors() counts it as a constructor!
public OuterClass foo(){
return new OuterClass(10);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment