How to Unit Test Your Annotation Processor using jOOR

Annotation processors can be useful as a hacky workaround to get some language feature into the Java language. jOOQ also has an annotation processor that helps validate SQL syntax for: Plain SQL usage (SQL injection risk) SQL dialect support (prevent using an Oracle only feature on MySQL) You can read about it more in detail … Continue reading How to Unit Test Your Annotation Processor using jOOR

How to Compile a Class at Runtime with Java 8 and 9

In some cases, it's really useful to be able to compile a class at runtime using the java.compiler module. You can e.g. load a Java source file from the database, compile it on the fly, and execute its code as if it were part of your application. In the upcoming jOOR 0.9.8, this will be … Continue reading How to Compile a Class at Runtime with Java 8 and 9

Correct Reflective Access to Interface Default Methods in Java 8, 9, 10

When performing reflective access to default methods in Java, Google seems to fail us. The solutions presented on Stack Overflow, for instance, seem to work only in a certain set of cases, and not on all Java versions. This article will illustrate different approaches to calling interface default methods through reflection, as may be required … Continue reading Correct Reflective Access to Interface Default Methods in Java 8, 9, 10

A neater way to use reflection in Java

Reflection in Java really feels awkward. The java.lang.reflect API is very powerful and complete, and in that sense also very verbose. Unlike in most scripting languages, there is no convenient way to access methods and fields dynamically using reflection. By convenient, I mean things like this // PHP $method = 'my_method'; $field = 'my_field'; // … Continue reading A neater way to use reflection in Java