Java, convert between two different generic instances -
i want make adapter interface (and implementations) use multiple similar external libraries.
for example, there interfaces of external libraries. these libraries guide implement converter
, register extend features.
lib a
public interface aconverter<s, d> { d convert(s source); }
lib b
public interface bconverter<s, d> { d convert(s source); }
both interfaces specify same method.
what want use own myconverter
interface.
public interface myconverter<s, d> { d convert(s source); }
a user implements class , library converts implementation either liba's implementation of aconverter
or libb's implementation of bconverter
. possible?
edit:
i not want factory pattern or extends liba interface , libb interface. myconverter core library, liba , libb external plugable libraries.
what trying is,
public alibadapter { aconverter change(myconverter convert) { /** * can do? */ return aconverter; } }
your interface can extend existing interfaces:
public interface myconverter<s, d> extends aconverter<s, d>, bconverter<s, d> { ... }
you can use in place of either 1 of library interfaces.
if methods have same name (convert
), can overridden. else you'd have make sure call implementations own method using java 8 default method implementations.
Comments
Post a Comment