I have a script like the following where there is a class Worldwith only a private constructor and another class App.
As shown in the code, a new class Worldcan be created inside the class App, despite its only private constructor World.
It is forbidden in Java, and I thought it was forbidden in groovy, but it Appworks without errors.
class World {
private World() {
}
}
class App {
static void main(String[] args) {
def world = new World()
println world
}
I could not understand how this is possible in groovy. How can another class instantiate a class with only a private constructor in groovy?
source
share