Sun Blogs – Understanding Inception using try-with-resources

by InceptionEnding

in Inception Ending

“After viewing the film “Inception,” I was inspired to use the new try-with-resources statement to summarize the film:

    public static void main(String... args) {
        try(CloseableDreamLevel dl1 =
            kickOnClose(createCityScape(firstClassCabin)) ) {
            try(CloseableDreamLevel dl2 =
                 kickOnClose(createHotel(dl1))) {
                 try(CloseableDreamLevel dl3 =
                     kickOnClose(createSnowMountainFortress(dl2))) {
                     inception();
                     try(CloseableDreamLevel dl4 =
                         kickOnClose(enterLimbo(dl3))) {
                         findTheLost();
                     }
                 }
            }
        }
    }
    private static DreamLevel enterLimbo(DreamLevel dl) {
        return
            new DreamLevel() {
                void kick() {
                    try {
                    if ((new java.util.Random()).nextBoolean())
                    Thread.currentThread().sleep(Integer.MAX_VALUE);
                    } catch (InterruptedException ie) {}
                }
            };
    }

http://blogs.sun.com/darcy/entry/understanding_inception_using_try_with

Leave a Comment

Previous post:

Next post: