Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Is it possible to somehow prohibit anonymously subclassing of a specific class? For instance, with a plain public parent class: public class Parent { } Extending this class should not be pos...
#1: Initial revision
Prevent anonymously subclassing
Is it possible to somehow prohibit _anonymously_ subclassing of a specific class? For instance, with a plain public parent class: ``` public class Parent { } ``` Extending this class should not be possible with an unnamed, anonymous subclass: ``` var myClass = new Parent() { ... } ``` However, all other forms of subclassing or usage should work, such as: ``` public class Child extends Parent { public static Object feelingLucky(boolean really) { return really ? new Child() : new Parent(); } } ```