Java 17: implementing Accessing Private Fields of Superclass in Reflection with Lombok-Generated Getters
I'm confused about I'm not sure how to approach I'm working on a project and hit a roadblock... I've been struggling with this for a few days now and could really use some help... I'm working with a question in my Java 17 application where I need to access private fields of a superclass using reflection, but I'm running into unexpected behavior. I have a superclass annotated with Lombok's `@Getter`, and a subclass that tries to access its private fields using reflection. Despite the getters being generated, when I try to invoke them, I get a `java.lang.IllegalAccessException`. Here’s an example of my code: ```java import lombok.Getter; @Getter public class SuperClass { private String superField = "Hello from SuperClass!"; } public class SubClass extends SuperClass { public void accessSuperField() throws Exception { Field field = SuperClass.class.getDeclaredField("superField"); field.setAccessible(true); String value = (String) field.get(this); System.out.println(value); } } public class Main { public static void main(String[] args) { try { new SubClass().accessSuperField(); } catch (Exception e) { e.printStackTrace(); } } } ``` When I run this code, I expect to see "Hello from SuperClass!" printed, but instead I get: ``` java.lang.IllegalAccessException: Class SubClass want to access a member of class SuperClass with modifiers "private" ``` I’ve checked that the field is indeed private, and I'm using `setAccessible(true)`, but I wonder if Lombok's annotations are interfering. I've also tried removing the Lombok annotations and manually implementing the getter method, but that doesn't resolve the scenario either. Is there a specific configuration or a workaround that I need to consider when using Lombok with reflection? I’ve looked into Lombok’s documentation but couldn’t find any mention of this particular scenario. Any help would be greatly appreciated! I'm working on a CLI tool that needs to handle this. Thanks for taking the time to read this! The project is a desktop app built with Java. What's the best practice here? Any help would be greatly appreciated! I'm working with Java in a Docker container on Windows 11. What's the best practice here? I'm working in a CentOS environment. Is this even possible?