Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java: Общие вопросы > generic


Автор: марина 6.4.2007, 15:34
Это интерфейс соединия
Код

public interface IConnectionModel extends IConnection, IConnectionSchema {
}


Это интерфейс слоя
Код

public interface ILayerModel extends ILayer, ILayerSchema {
}


Интерфейс ILayer:
Код

public interface ILayer {
    List<IConnection> getInputConnections();

}



Интерфейс ILayerSchema:
Код

public interface ILayerSchema {
    List<IConnectionSchema> getInArrows();

}


Это имплементация слоя
Код

public class LayerModel implements ILayerModel {
    private List<IConnectionModel> myOutputConnections;
    private List<IConnectionModel> myInputConnections;

    LayerModel() {
        myOutputConnections = new LinkedList<IConnectionModel>();
        myInputConnections = new LinkedList<IConnectionModel>();
    }

    public List<IConnectionSchema> getInArrows() {
        return Collections.unmodifiableList(myInputConnections);
    }

    public List<IConnection> getInputConnections() {
        return Collections.unmodifiableList(myInputConnections);
    }



}


проблема здесь :
Код

    public List<IConnectionSchema> getInArrows() {
        return Collections.unmodifiableList(myInputConnections);
    }

    public List<IConnection> getInputConnections() {
        return Collections.unmodifiableList(myInputConnections);
    }



как это переделать чтоб заработало?

Автор: LSD 6.4.2007, 15:58
Код
interface IConnectionSchema
{
}

interface IConnection
{
}

interface ILayerSchema
{
  List<? extends IConnectionSchema> getInArrows();
}

interface ILayer
{
  List<? extends IConnection> getInputConnections();
}

interface ILayerModel extends ILayer, ILayerSchema
{
}

interface IConnectionModel extends IConnection, IConnectionSchema
{
}

class LayerModel implements ILayerModel
{
  private List<IConnectionModel> myOutputConnections;
  private List<IConnectionModel> myInputConnections;

  LayerModel()
  {
    myOutputConnections = new LinkedList<IConnectionModel>();
    myInputConnections = new LinkedList<IConnectionModel>();
  }

  public List<? extends IConnectionSchema> getInArrows()
  {
    return Collections.unmodifiableList(myInputConnections);
  }

  public List<? extends IConnection> getInputConnections()
  {
    return Collections.unmodifiableList(myInputConnections);
  }
}


Добавлено через 28 секунд
Или:
Код
interface IConnectionSchema
{
}

interface IConnection
{
}

interface ILayerSchema<T extends IConnectionSchema>
{
  List<T> getInArrows();
}

interface ILayer<T extends IConnection>
{
  List<T> getInputConnections();
}

interface ILayerModel<T1 extends IConnection, T2 extends IConnectionSchema> extends ILayer<T1>, ILayerSchema<T2>
{
}

interface IConnectionModel extends IConnection, IConnectionSchema
{
}

class LayerModel implements ILayerModel<IConnectionModel, IConnectionModel>
{
  private List<IConnectionModel> myOutputConnections;
  private List<IConnectionModel> myInputConnections;

  LayerModel()
  {
    myOutputConnections = new LinkedList<IConnectionModel>();
    myInputConnections = new LinkedList<IConnectionModel>();
  }

  public List<IConnectionModel> getInArrows()
  {
    return Collections.unmodifiableList(myInputConnections);
  }

  public List<IConnectionModel> getInputConnections()
  {
    return Collections.unmodifiableList(myInputConnections);
  }
}

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)