Questions tagged [java-15]

Use this tag for questions specific to Java 15, which is version 15 of the Java platform, released on September 15, 2020. In most cases you should also specify the java tag.

This release is the Reference Implementation of version 15 of the Java SE Platform, as specified by JSR 390 in the Java Community Process.

111 questions
53
votes
4 answers

What is the point of extending a sealed class with a non-sealed class?

I don't really understand why there is a non-sealed keyword in JEP 360/Java 15. For me, an extension of a sealed class should only be final or a sealed class itself. Providing the "non-sealed" keyword will invite the developer for hacks. Why are we…
Ayox
  • 691
  • 5
  • 15
27
votes
6 answers

String interpolation in Java 14 or 15

Since I am using Java 14 and 15 preview features. Trying to find the string interpolation in java. The closest answer I found is String.format("u1=%s;u2=%s;u3=%s;u4=%s;", u1, u2, u3, u4) Since the answer which I got from lots fo references are old…
San Jaisy
  • 15,327
  • 34
  • 171
  • 290
23
votes
3 answers

How to use Nashorn in Java 15 and later?

I have an existing Spring Boot application that is non-modular and uses Nashorn. The application works well on Java 14. After adding the Maven coordinates of the new Nashorn available for Java 15, the application fails while starting the script…
Aswath Murugan
  • 505
  • 2
  • 4
  • 12
22
votes
1 answer

C-style arrays do not work with records anymore

I was previously using this contrived code record Foo(int bar[]) {} which is making use of the C-style array-notation. And it compiled fine in Java 15. Now, all of the sudden, with the official release of records in Java 16, it does not compile…
Zabuzard
  • 25,064
  • 8
  • 58
  • 82
21
votes
3 answers

Set value to one of the property in Java 15 record

I am using Java 15 preview feature record in my code, and defined the record as follow public record ProductViewModel ( String id, String name, String description, float price …
San Jaisy
  • 15,327
  • 34
  • 171
  • 290
21
votes
7 answers

What is the point of a “sealed interface” in Java?

Sealed classes and sealed interfaces were a preview feature in Java 15, with a second preview in Java 16, and now proposed delivery in Java 17. They have provided classic examples like Shape -> Circle, Rectangle, etc. I understand sealed classes:…
Player_Neo
  • 1,413
  • 2
  • 19
  • 28
20
votes
4 answers

How can i add variables inside Java 15 text block feature?

Just came across a new feature in Java 15 i.e. "TEXT BLOCKS". I can assume that a variable can be added inside a text block by concatenating with a "+" operator as below: String html = """ …
Ritusmoi Kaushik
  • 211
  • 1
  • 2
  • 6
18
votes
1 answer

static final fields vs TrustFinalNonStaticFields

Suppose I have this simple method: static final Integer me = Integer.parseInt("2"); static int go() { return me * 2; } For javac, me is not a constant (according to the JLS rules), but for JIT most probably is. I tried to test this with: …
Eugene
  • 117,005
  • 15
  • 201
  • 306
15
votes
0 answers

java 15 Nanoseconds precision causing issues on Linux environment

I have a best practices question with regards to mapping Instant to PostgreSQL TIMESTAMP. We've updated our app to Java 15 and the new enhancement of the system clock to nanosecond precision ( https://bugs.openjdk.java.net/browse/JDK-8242504 ) is…
catch22
  • 1,564
  • 1
  • 18
  • 41
13
votes
3 answers

What is the difference between a final and a non-sealed class in Java 15's sealed-classes feature?

I have the following sealed interface (Java 15): public sealed interface Animal permits Cat, Duck { String makeSound(); } This interface is implemented by 2 classes: public final class Cat implements Animal { @Override public String…
Michael Kemmerzell
  • 4,802
  • 4
  • 27
  • 43
10
votes
2 answers

Lambda expressions and anonymous classes don't work when loaded as hidden classes

I am trying to compile and load dynamically generated Java code during runtime. Since both ClassLoader::defineClass and Unsafe::defineAnonymousClass have serious drawbacks in this scenario, I tried using hidden classes via Lookup::defineHiddenClass…
Duff
  • 195
  • 9
10
votes
2 answers

How can I continue to use Javascript in Java 15 onwards

In my Java application a small put important feature is to be able to rename audio files based on their metadata (e.g album/artist -title) and the mask is specified using Javascript, this makes for a very flexible and powerful renaming feature. I…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
9
votes
1 answer

How to use Java version 15 in Eclipse 2020-09

I'm trying to run the new Java 15 features under Eclipse 2020-09. I have installed OpenJDK 15 and set it under "Installed JRE": Nevertheless I cannot set this version as compiler version (only till version 14): What am I doing wrong?
mrbela
  • 4,477
  • 9
  • 44
  • 79
8
votes
2 answers

Java record vs lombok @Value

Records are a new language feature since Java 14 (first preview) and Java 15 (second preview). As per my understanding they will be used to reduce boilerplate code in immutable data objects. So this sigle line: public record Person (String…
pepevalbe
  • 1,340
  • 6
  • 18
7
votes
1 answer

Java record constructor invisible through reflection

I'm playing with Java 15's new records feature, and how it interacts with reflection. I've run into some strange behaviour, where I can sometimes access a record's constructor via reflection, and sometimes not. For example, given the following Java…
jqno
  • 15,133
  • 7
  • 57
  • 84
1
2 3 4 5 6 7 8