MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/5xbnvu/the_java_nazi/dehvzza/?context=3
r/java • u/onebit • Mar 03 '17
47 comments sorted by
View all comments
11
This is why I've started just using interfaces for Utility classes. You get the same benefit, except it blows up at compile time instead of at runtime.
3 u/zjs Mar 04 '17 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. 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!
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!
11
u/CubsThisYear Mar 03 '17
This is why I've started just using interfaces for Utility classes. You get the same benefit, except it blows up at compile time instead of at runtime.