Я получил эту ошибку компиляции в моем коде:Метод «XXX» является ambigious для типа
Метод добавления (UComponent оценочного, KopiAlignment ограничений); неоднозначна для типа DBlock ...
Я хочу создать интерфейс UBlock сделать абстракции для существующего класса DBlock
Вот код:
Интерфейс UBlock:
public interface UBlock extends UComponent, BlockListener {
public void add(UComponent comp, KopiAlignment constraints);
}
Класс DBlock:
public class DBlock extends JPanel implements UBlock {
public void add(UComponent comp, KopiAlignment constraints) {
}
}
я вызываю метод добавления в другом классе:
private DBlock blockView;
blockView.add(displays[i], new KopiAlignment(chartPos + leftOffset, i + 1, 1, false));
Когда я удаляю реализацию UBlock от DBlock Ошибка больше не существует, а вот так называемый метод:
/**
* Adds the specified component to the end of this container.
* Also notifies the layout manager to add the component to
* this container's layout using the specified constraints object.
* This is a convenience method for {@link #addImpl}.
* <p>
* Note: If a component has been added to a container that
* has been displayed, <code>validate</code> must be
* called on that container to display the new component.
* If multiple components are being added, you can improve
* efficiency by calling <code>validate</code> only once,
* after all the components have been added.
*
* @param comp the component to be added
* @param constraints an object expressing
* layout contraints for this component
* @exception NullPointerException if {@code comp} is {@code null}
* @see #addImpl
* @see #validate
* @see javax.swing.JComponent#revalidate()
* @see LayoutManager
* @since JDK1.1
*/
public void add(Component comp, Object constraints) {
addImpl(comp, constraints, -1);
}
Так как может Я решаю этот вопрос?
Включите ваше значение. Эта ошибка означает, что используемое вами значение потенциально может соответствовать более чем одному методу, а компилятор не может определить, какой из них выбрать. – CodeChimp