I am using java 1.8. And I came to know that WToolkit is final in java 1.8. But I need to extend this class. Could you please tell me ways to extend this class? I read articles related to javaagent mechanism. If any one knows about agent mechanism, please explain.
Asked
Active
Viewed 92 times
0
-
5no by defination , final class means it cannot be extended. Could you tell why you want to do so, i believe your functionality can be achieved by some other way.You can consider wraping it. – Panther Jul 27 '15 at 06:26
-
possible duplicate of [How to extend a final class in Java](http://stackoverflow.com/questions/13294629/how-to-extend-a-final-class-in-java) – Panther Jul 27 '15 at 06:29
-
6There is no class named `WToolkit` in the public API of the JDK. Do you mean the class [`sun.awt.windows.WToolkit`](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/sun/awt/windows/WToolkit.java?av=f)? That is an internal class in the JDK that you [should not be using](http://www.oracle.com/technetwork/java/faq-sun-packages-142232.html). – Jesper Jul 27 '15 at 06:36
-
2What are you trying to achieve, specifically? There are probably better ways to do whatever it is that do not require extending a final class in a private API. – clstrfsck Jul 27 '15 at 07:03
-
X-Y problem? Why do you think you need to extend this class? – erickson Jul 30 '15 at 13:20
1 Answers
0
You can use javaagent to inject code into any Java method, thereby changing its behavior, similar to overriding it in an extended class. See Tutorials about javaagents. Good chance there is an easier solution to what you are trying to achieve. What are you trying to achieve?