Observer is deprecated in Java 9. What should we use instead of it?

Why is that? Does it mean that we shouldn’t implement observer pattern anymore? Answering the latter part first – YES, it does mean you shouldn’t implement Observer and Obervables anymore. Why were they deprecated – They didn’t provide a rich enough event model for applications. For example, they could support only the notion that something … Read more

How to solve InaccessibleObjectException (“Unable to make {member} accessible: module {A} does not ‘opens {package}’ to {B}”) on Java 9?

The exception is caused by the Java Platform Module System that was introduced in Java 9, particularly its implementation of strong encapsulation. It only allows access under certain conditions, the most prominent ones are: the type has to be public the owning package has to be exported The same limitations are true for reflection, which … Read more

What is an illegal reflective access?

Apart from an understanding of the accesses amongst modules and their respective packages. I believe the crux of it lies in the Module System#Relaxed-strong-encapsulation and I would just cherry-pick the relevant parts of it to try and answer the question. What defines an illegal reflective access and what circumstances trigger the warning? To aid in … Read more

What is the difference between List.of and Arrays.asList?

Arrays.asList returns a mutable list while the list returned by List.of is immutable: List<Integer> list = Arrays.asList(1, 2, null); list.set(1, 10); // OK List<Integer> list = List.of(1, 2, 3); list.set(1, 10); // Fails with UnsupportedOperationException Arrays.asList allows null elements while List.of doesn’t: List<Integer> list = Arrays.asList(1, 2, null); // OK List<Integer> list = List.of(1, 2, … Read more

Replacements for deprecated JPMS modules with Java EE APIs

Instead of using the deprecated Java EE modules, use the following artifacts. JAF (java.activation) JavaBeans Activation Framework (now Jakarta Activation) is a standalone technology (available on Maven Central): <dependency> <groupId>com.sun.activation</groupId> <artifactId>jakarta.activation</artifactId> <version>1.2.2</version> </dependency> (Source) CORBA (java.corba) From JEP 320: There will not be a standalone version of CORBA unless third parties take over maintenance of … Read more

Failed to install android-sdk: “java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema”

Just had this error, solved by downloading the Android SDK Command-line Tools (latest) on Android Studio, under Preferences > Appearance & Behavior > System Settings > Android SDK > SDK Tools and re-running flutter doctor –android-licenses Finally, add the new tools to your PATH, in your .bashrc, .zshrc or similar, before the obsolete tools: export … Read more

Why does array[idx++]+=”a” increase idx once in Java 8 but twice in Java 9 and 10?

This is a bug in javac starting from JDK 9 (which made some changes with regard to string concatenation, which I suspect is part of the problem), as confirmed by the javac team under the bug id JDK-8204322. If you look at the corresponding bytecode for the line: array[i++%size] += i + ” “; It … Read more

How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

The JAXB APIs are considered to be Java EE APIs and therefore are no longer contained on the default classpath in Java SE 9. In Java 11, they are completely removed from the JDK. Java 9 introduces the concepts of modules, and by default, the java.se aggregate module is available on the classpath (or rather, … Read more

tech