In Kotlin, how does GSON.fromJson(…) manage to mutate a read-only field of an existing object?

In Kotlin, how can an instance’s read-only val field be mutated? In the following Kotlin code, gson.fromJson(…) gets a Thing(0) from the InstanceCreator and somehow manages to mutate value from 0 to …

Compare objects and create a new one similar to one of them

I want to compare 2 objects and create a new one with the values of the second if its values are not null. Otherwise the values of the first one should be copied to the object created. My problem is …

Akka Quickstart: An illegal reflective access operation has occurred

When running the official Akka Quickstart on my Mac terminal, I get this error: Getting org.scala-sbt sbt 1.2.8 … WARNING: An illegal reflective access operation has occurred WARNING: Illegal …

Why is `getDeclaredAnnotations()` returning an empty list when an annotation is present?

The Javadocs entry for getDeclaredAnnotations say the following: Returns annotations that are directly present on this element. This method ignores inherited annotations. If there are no annotations …

deep copy using reflection java

I can’t get a container from the class field using reflection. I tried the method below, but got an exception: Exception in thread “main” java.lang.UnsupportedOperationException at java….

How to fix this unchecked assignment warning?

var blks = ReflectionHelper.getClasses(“PACKAGE_NAME”); var blockRta = RuntimeTypeAdapterFactory.of(Block.class); for (var c : blks) { if (Block.class.isAssignableFrom(c)) { blockRta….

Referencing packages in java without using String

Is there a way to reference a package in java in code without using a String? Let me explain myself: I’ve a function that fetches all object contained in a package, but I’ve to reference that …

Scanner TypeAnnotationsScanner was not configured, when used from a referenced library

I have a class which uses org.reflections.Reflections to get annotations in classes in the class path. When i use it in the same project everything works fine, but when i export it as a JAR and refer …

How to parse a String variable into any data type in Java?

I want to build a method that can convert a String value to a given Field object data type through Java Reflection. Here is my code: String value = …; Class clazz = …

Reflection generic get field value

I am trying to obtain a field’s value via reflection. The problem is I don’t know the field’s type and have to decide it while getting the value. This code results with this exception: Can not set …