Как универсальные типы работают для геттеров и сеттеров? - PullRequest
0 голосов
/ 25 октября 2018

Я пытаюсь создать геттеры и сеттеры для двумерной сетки, используя универсальные типы, но я несколько запутался в том, как относиться к ним по-разному, так как я получаю ошибки.Вот методы с некоторыми javadoc о том, что они должны делать.

public class IntGrid2D<T> implements IIntGrid2D{
private IIntPoint2D p;
private T v;
 /**
 * Sets the value at a point on the grid, replacing the previous value if any.
 * @param p The coordinate to set the value of
 * @param v The value to set at the coordinate
 * @throws OffGridException if p is outside the grid
 */
public void setPoint(IIntPoint2D p, T v) throws OffGridException{
    this.p = p;
    this.v = T;

}


/**
 * Gets the value at a point on the grid
 * @param p The coordinate to get the value of
 * @return the stored value
 * @throws OffGridException if p is outside the grid
 */
public T getPoint(IIntPoint2D p) throws OffGridException{
    return p;
}
/**
 * Gets the coordinate for the upper left most location
 * @return an IIntPoint that is the coordinate of the upper left corner
 */
public IIntPoint2D getUpperLeftCorner(){
}
/**
 * Gets the coordinate for the lower right most location
 * @return an IIntPoint that is the lower right corner
 */
public IIntPoint2D getLowerRightCorner(){
}
}

1 Ответ

0 голосов
/ 25 октября 2018

Изменить getPoint на это:

public T getPoint(IIntPoint2D p) throws OffGridException{
    return v;
}
...