Pleiades Eclipse 2020-03 release ~ Java 14 Let's try new features!

Pleiades All in One Eclipse 2020-03 has been released. Try out the new features for the migration from the current Java 11 LTS to the 2021 Java 17 LTS. Java Full Edition of Pleiades All in One is just unzipped, there is no need to install Java or set environment variables, and various settings of Eclipse are automatically done, so you can immediately use Java 14 with Japaneseized Eclipse. I will.

** Pleiades All in One Download ** http://mergedoc.osdn.jp/ splash.png

Creating a Java 14 project

Simply select 14 of the Java 6, 7, 8, 11, 14 configured by default. No Java download or installation path setting is required. create_project.png

If you want to use the non-standard preview feature, set the project properties. Project> Right Click> Properties java14_setting.png

Convenient function for pasting Java code text

This is a function that has been around for a long time, but if you just paste the Java source code text directly under src in the tree of Package Explorer instead of a file, the following behavior will be easy. You don't need to right click New> Class> Dialog.

Java 14 new features

Sample code for switches, records, text blocks, and pattern matching. It is in one class so that it is easy to paste and try.

import static java.lang.System.*;
import java.time.Month;

class Demo {

	public static void main(String[] args) {

		//--------------------------------------------------
		// switch (Java 14 standard)
		{
			//Multiple labels-result: "Hello\nWorld\n"
			var i = 1;
	    	switch (i) {
				case 0, 1, 2: out.println("Hello");
				default :  out.println("World");
			}
		}
		{
			//Arrow-result: Hello
			var i = 2;
	    	switch (i) {
	    		case  2 -> out.println("Hello");
	    		default ->  out.println("World");
			}
		}
		{
			//switch expression-result:Big moon
			var month = Month.MARCH;
			String day = switch(month) {
				case APRIL, FEBRUARY, JUNE, NOVEMBER, SEPTEMBER -> "Small moon";
				case AUGUST, DECEMBER, JANUARY, JULY, MARCH, MAY, OCTOBER -> "Big moon";
			};
			out.println(day);
		}

		//--------------------------------------------------
		//record (Java 14 preview)
		{
			//Inner record definition
			record Point(int x, int y) {}

			//getter automatic generation-result: 10
			out.println(new Point(10, 20).x());

			//toString automatic generation-result: Point[x=10, y=20]
			out.println(new Point(10, 20));

			//equals automatic generation-result: true
			out.println(new Point(10, 20).equals(new Point(10, 20)));
		}

		//--------------------------------------------------
		//Text block (Java 14 second preview)
		{
			//result: "Hello\n    World"
			String s = """
					Hello
						World
							""";
			System.out.println(s);
		}

		//--------------------------------------------------
		//instanceof pattern matching (Java 14 preview)
		{
			//Assign with instanceof-result: 3
			Object object = 1;
			if (object instanceof Integer i) {
				out.println(i + 2);
			}
			//Type and value compound condition
			if (object instanceof Integer i && i == 1) {
				out.println(i);
			}
		}

		//--------------------------------------------------
		//NullPointerException detailed output (Java 14 standard)
		//In the VM argument of the execution configuration-XX:+Added ShowCodeDetailsInExceptionMessages
		//result:
		/*
		Exception in thread "main" java.lang.NullPointerException:
			Cannot invoke "String.length()" because "s" is null
				at Demo.main(Demo.java:78)
		*/
		{
			String s = null;
			s.length();
		}
	}
}

Recommended Posts

Pleiades Eclipse 2020-03 release ~ Java 14 Let's try new features!
Try Eclipse 4.7 Oxygen New 30+ / Java 10 var!
java1.8 new features
New features from Java7 to Java8
Try running Selenuim 3.141.59 in eclipse (java)
Java 9 new features and sample code
About the new Java release model @ Seki Java (2018/07/20)
Java features
Let's try WebSocket with Java and javascript!
Java features
Let's keep this in mind What's new in Java 9
I touched on the new features of Java 15
Let's use Java New FileIO! (Introduction, for beginners)
Let's study Java
Try Java 8 Stream
About Java features
Roughly try Java 9
[Tutorial] Download Eclipse → Run the application with Java (Pleiades)
[Tutorial] Download Eclipse → Run Web application with Java (Pleiades)