Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Java Class non-final via Reflection API

I have a Java class similar to the following one:

public final class Node {
    public Node() {}
}

I have learned already how to change change the accessibility of 'final' fields via the reflection API, but is this also possible for classes? Can I turn a final class into a non-final class at runtime?

like image 290
user982247 Avatar asked May 23 '12 16:05

user982247


1 Answers

You can re-write a class file using a library like ASM.

There may be no point changing the final status of a class at runtime as it needs to be non-final at compile time to compile a sub-class.

like image 122
Peter Lawrey Avatar answered Sep 30 '22 21:09

Peter Lawrey