If you don't want to use sealed classes like max mentioned, it's possible to use a library like classgraph to accomplish what you want. Sealed classes probably not a bad choice though especially since you can place them outside the same file now I think