Creating a class in the same package as in the external library in order to use package-private classes

Viewed 248

I am creating an object of a public library class that uses an object of some package-private class in its code. That package-private class has some malformed logic. Now I want to change the logic. Any idea how to do that other than downloading the library, changing its code and then importing it as a module?

What I have done so far:

I created a new class with the same name by creating a new custom package with the same name. I mean I created a package at my root folder com.abc.xyz and created a class X in it. But the problem is that my code is still using the old library version of the class X instead of this new one. I checked this by attaching debugger points in my class X. Interesting things is when I'm navigating through Android Studio IDE's code navigation tools, it is showing that my Y class is using my version of X class and not of the library author. So the second question is that is this technique even possible in Kotlin, if yes then what I'm doing wrong?

I got the above idea by reading the below lines somewhere:

With Java, the encapsulation can be easily broken, because external code can define classes in the same packages used by your code and thus get access to your package-private declarations

0 Answers
Related