简体   繁体   中英

Understanding Java Converter interface

I need to add the interface called Converter<Destination, Source> to provide conversion facilities. I'd write it as follows:

public interface Converter<Destination, Source>{
    public Destrination convert(Source o);
}

I'm using thrid-party libraries which always have converter interfaces satisfied my needs more-or-less. Should I consider to use them instead of adding the new interface? I'd say no, it would be better off creating a new interface because otherwise we would couple our code to the library which interface we use.

So, what would be the right choice?

Since you have Guava in your classpath, there's no need to introduce a brand new interface that does the same as Guava's Function , which is defined as:

public interface Function<F,T> {
    public T apply(F input);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM