Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert not null of a Singleton Object

Is it necessary to Assert.notNull of a Singleton Object?

I have a class:

public class ComponentFactory {
    private static LibraryFrame libraryFrame;

    public static synchronized LibraryFrame getLibraryFrame() {
        if (libraryFrame == null) {
           libraryFrame = new LibraryFrame();
        }
        return libraryFrame;
    }
}

Now is it needed to use as:

LibraryFrame libraryFrame = ComponentFactory.getLibraryFrame();
Assert.notNull(libraryFrame);
// other part

Here Assert class is org.springframework.util.Assert.

If Assertion failed is there anyway to call System.exit(0) after failure occurred?

like image 427
Tapas Bose Avatar asked Mar 29 '26 22:03

Tapas Bose


1 Answers

The Assert is not necessary since the LibraryFrame instance will always be initialized at this point.

like image 123
Kai Sternad Avatar answered Apr 02 '26 03:04

Kai Sternad