[JAVA] Is there an instance even if the constructor fails?

public class Main {

    public static Main me;

    public Main() throws Exception {
        this.me = this;
        throw new Exception("constructor error.");
    }

    public void method() {
        System.out.println("It's me");
    }

    public static Main main() {
        return me;
    }

    public static void main(String... args) {
        try {
            Main main = new Main();
        } catch (Exception e) {
            System.out.println("constructor failed.");
        }

        Main main = Main.main();
        main.method();
    }
}

result

constructor failed.
It's me

Recommended Posts

Is there an instance even if the constructor fails?
[Ruby] What is an instance?
What is the constructor for?
It doesn't work if the Map key is an array
How to validate subsequent tests even if the test fails
What is the difference between an action and an instance method?
How to output the value when there is an array in the array
Isn't it reflected even if the content is updated in Rails?
An active hash that can be treated as data even if it is not in the database
[Java] Conditional branching is an if statement, but there is also a conditional operator.
Get the type of an array element to determine if it is an array
Is there an engineer who hasn't validated the Json column in Rails?
Spring Autowired is written in the constructor
If the parameter is an array, how to include it in Stopara's params.permit
How to check if an instance variable is defined in a Ruby class
Setting method that the size does not change even if CSS is changed
Even if I want to convert the contents of a data object to JSON in Java, there is a circular reference ...
Can't I use RXTX? Is there an alternative?
[August 2020] If the installation of cool.io / puma fails
Creating an object without going through the constructor