Код: Выделить всё
/** Never change *a line* of this or some angry monster will fall from the opening skies talking obscure reasons not to mess with this */
public interface IllFindStuffNoWorries {
STUFF findById(String id);
STUFF findById(Long id);
STUFF findById(UUID id);
... and so on
}
Но оказывается, что все ВЕЩИ проекта имеют метод getId(), который возвращает один из типов, которые готов обрабатывать связанный с реализацией IllFindStuffNoWorries.
Поэтому я ввел:
Код: Выделить всё
public interface IveGotId { ID getId(); }
Код: Выделить всё
public interface TypicalFinder { //get it ? typical because types ... ha ha that sounded hilarious in my head ...
STUFF findById(ID id);
}
Код: Выделить всё
/** Change as little as you can there */
public class Something {
...
String getId(){ return id; }
...
}
public interface SomethingFinder extends IllFindStuffNoWorries {}
Код: Выделить всё
/** Change as little as you can there */
public class Something implements IveGotId {
...
@Override String getId(){ return id; }
...
}
public interface SomethingFinder extends IllFindStuffNoWorries, TypicalFinder {}
< pre class="lang-none Prettyprint-override">
Код: Выделить всё
/home/stackOverflowUserAr3s/projects/hot-mess/src/main/java/some/where/impl/SomethingFinderImpl.java:12:42
java: reference to findById is ambiguous
both method findById(ID) in new.mess.TypicalFinder
and method findById(java.lang.String) in old.mess.IllFindStuffNoWorries
match
Пытаюсь ли я полагаться на устаревшее мышление?
Правда ли @FunctionalInterface - это своего рода путь в моем случае (только один метод, который меня интересует)?
Это интерфейсы, расширенные интерфейсом... Это не какое-то причудливое намерение множественных реализаций, то есть сочетание контрактов, которые удобно перекрываются и могут быть выполнены с помощью одной реализации.
Подробнее здесь: https://stackoverflow.com/questions/662 ... -ambiguous