Public Repository

Last pushed: 2 years ago
Short Description
An image for testing JEP 286: Local-Variable Type Inference for Java
Full Description

JEP 286 enhances the Java Language to extend type inference to declarations of local variables with initializers. See more about it: http://iteratrlearning.com/jep286.html

How it works

You can simply run the command below to see the version of javac:

$ docker run --rm kodcu/jep286
javac 9-internal

Let's say in your current directory you have a .java file called Example containing the following structure:

import java.util.stream.Stream;
import java.util.ArrayList;

public class Example {
    public static void main(String...args) {    
        var messages = Stream.of(new Message("Hello"), new Message("world"));

        messages.map(Message::getContent)
                .forEach(System.out::println); // Hello World

        var answer = 40;        
        System.out.println(answer + 2); // prints 42

        var list = new ArrayList<String>();
        list.add("Hello");
        list.add("Duke");

        System.out.println(list.getClass()); // class java.util.ArrayList
        System.out.println(list); // [Hello, Duke]
    }

    static class Message {
        private String content;
        public Message(String content) {
            this.content = content;
        }
        public String getContent() {
            return this.content;
        }
    }
}

You can compile and run this class in order to see how JEP 286 interprets those statements. Mount your current directory into a directory in your container's file system (let's say src) to copy Example.java into the container, go into this directory, compile and run the code as follows:


$ docker run --rm -v $(PWD):/src -w /src kodcu/jep286 /bin/bash -c "javac Example.java && java Example"
Hello
world
42
class java.util.ArrayList
[Hello, Duke]
Docker Pull Command
Owner
kodcu

Comments (0)