alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (ImplicitFinal.java)

This example Java source code file (ImplicitFinal.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

assertionerror, autocloseable, implicitfinal, ioexception, not, shouldn't, suppresswarnings

The ImplicitFinal.java Java example source code

/*
 * @test  /nodynamiccopyright/
 * @bug 6911256 6964740 6965277 7013420
 * @author Maurizio Cimadamore
 * @summary Test that resource variables are implicitly final
 * @compile/fail/ref=ImplicitFinal.out -XDrawDiagnostics ImplicitFinal.java
 */

import java.io.IOException;

class ImplicitFinal implements AutoCloseable {
    public static void main(String... args) {
        try(ImplicitFinal r = new ImplicitFinal()) {
            r = null; //disallowed
        } catch (IOException ioe) { // Not reachable
            throw new AssertionError("Shouldn't reach here", ioe);
        }

        try(@SuppressWarnings("unchecked") ImplicitFinal r1 = new ImplicitFinal()) {
            r1 = null; //disallowed
        } catch (IOException ioe) { // Not reachable
            throw new AssertionError("Shouldn't reach here", ioe);
        }

        try(final ImplicitFinal r2 = new ImplicitFinal()) {
            r2 = null; //disallowed
        } catch (IOException ioe) { // Not reachable
            throw new AssertionError("Shouldn't reach here", ioe);
        }

        try(final @SuppressWarnings("unchecked") ImplicitFinal r3 = new ImplicitFinal()) {
            r3 = null; //disallowed
        } catch (IOException ioe) { // Not reachable
            throw new AssertionError("Shouldn't reach here", ioe);
        }
    }
    public void close() throws IOException {
        throw new IOException();
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java ImplicitFinal.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.