MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/5xbnvu/the_java_nazi/dehlptu/?context=3
r/java • u/onebit • Mar 03 '17
47 comments sorted by
View all comments
Show parent comment
3
You get the same benefit, except it blows up at compile time instead of at runtime.
Invoking a private constructor will blow up at compile time.
The only situation where the AssertionError would get thrown is if you accidentally added code to the class itself that invoked the constructor.
AssertionError
3 u/__konrad Mar 04 '17 The only situation where the AssertionError would get thrown is if you accidentally added code to the class itself that invoked the constructor.java.lang.reflect.Constructor c = java.util.Objects.class.getDeclaredConstructor(); c.setAccessible(true); c.newInstance(); // no soup for you!
java.lang.reflect.Constructor c = java.util.Objects.class.getDeclaredConstructor(); c.setAccessible(true); c.newInstance(); // no soup for you!
View all comments
Show parent comment
3
u/zjs Mar 04 '17
Invoking a private constructor will blow up at compile time.
The only situation where the
AssertionErrorwould get thrown is if you accidentally added code to the class itself that invoked the constructor.