There is a third-party library whose spy class object is needed. But the only class constructor is protected, which accepts 1 String parameter. To create a class 1 heir to the test, I think it is not correct. Maybe someone knows how to create an instance of this class and pass an argument?

  • Unclear. Does the protected modifier at the constructor prevent you from creating an instance of this class? You tried? ideone.com/sexhyT - Alexey Shimansky
  • Yes, just IDEA swore at it, I didn’t even compile. I was sure that it would not work. But in the end it worked, which is a bit strange. After all, if the constructor is prtotected, then you cannot create an instance of this class from another. I always thought so. - Maxim Drobyshev
  • Inside the package where the class is defined - you can do that. But this is the only condition of course - Aleksey Shimansky
  • I just thought default inside the package. - Maxim Drobyshev

0