0

I have a library class, that is, a class that I load from a JAR, the source code is outside of my control. We instanciate it in our project in several places, and a property of the created objects should be always set. Unfortunately there is no central settings for the library, so I have created a subclass:

public class MyClass extends LibraryClass {
    public MyClass() {
        super();
        super.setSomeProperty();
    }
}

and then I replaced all instanciation of LibraryClass with MyClass. It works fine, but I want to prevent myself and my collegues to instanciate a LibraryClass in the future.

Is it possible to mark the LibraryClass (or its constructor) as deprecated by Maven or by Eclipse or somehow else?

Géza
  • 481
  • 1
  • 3
  • 13
  • 3
    You cant mark a third party class as deprecated for that you need to have source code as without compiling it's not possible. – Ashutosh Dec 11 '19 at 17:02
  • Yes, I cannot mark a third party class as deprecated. But still, there are so many smart tools, perhaps one of them could result a simillar effect somehow. Any compiler warning would be helpful. – Géza Dec 12 '19 at 09:58
  • I would suggest one silly thing to you, you might try if you feel like doing so. Make a wrapper class to the library class you are using, now it's in your codebase, Do whatever you want to do with that class. – Ashutosh Dec 12 '19 at 12:16
  • Ashutosh Sharma: I did first exactly what you have suggested. The question is the next step: how to prevent myself and my collegues to instanciate a LibraryClass in the future. – Géza Dec 13 '19 at 16:51
  • My answer will remain the same, I don't see any other solution than writing it somewhere as a standard that we will not use this library anymore. – Ashutosh Dec 14 '19 at 17:50

0 Answers0