1

I have a class that implements two interfaces. One of this interfaces is defined in a second party jar and the other interface directly in my code.

Now I need to pass an object to a third party that only implements the interfaces I defined in my code. My doubt is if this will work just downcasting my object to the interface I define or even I downcast, this third party will still need the second party library as internally the class I pass still keeps a reference to the interface defined in the second party jar.

To visualize the scenario, some code...

Interface in my code:

public interface MyInterface {}

Interface in secondparty.jar:

public interface SecondpartyInterface {}

My object:

public MyObject implements MyInterface, SecondpartyInterface {}

Now the third party calls to a method in my code that should be something like:

private MyObject object;
public MyInterface getObject() {
    return (MyInterface)object;
}   

The third party has my.jar that contains MyInterface only. Will this work or the third party will need also the jar from the second party?

Thanks.

daniel sp
  • 937
  • 1
  • 11
  • 29

2 Answers2

0

when you export as a jar, if you have included classes from second party jars the third party will not need thee secon party jar or else Yes! it will be required

here is an example that shows How to create a jar with external libraries included in eclipse

Community
  • 1
  • 1
dev2d
  • 4,245
  • 3
  • 31
  • 54
0

Well it depends on one thing really, whether or not the original code is present as of runtime. If you are running a common main program (say some API that loads plugins), then it will likely not be an issue. Otherwise, you can shade your libraries so they are loaded in your jarfile, and then dependencies would either shade you or be run from your instance.

Rogue
  • 11,105
  • 5
  • 45
  • 71