创建具体类型的切片并将其转换为相应的界面

Having some issues creating a slice of interfaces and initiating it to its concrete type, any help would be greatly appretiated

Interface

type MatrixElement interface {
    GetValue() Element
    GetCoordinate() Coordinate
}

Concrete Implementation

type LocatableElement struct {
    value datastructures.Element
    coordinate datastructures.Coordinate
}

func (ele LocatableElement)GetValue() datastructures.Element {
    return ele.value
}

func (ele LocatableElement)GetCoordinate() datastructures.Coordinate {
    return ele.coordinate
}

func CreateLocatableElement(value datastructures.Element, coordinate datastructures.Coordinate) LocatableElement {
    return LocatableElement{
        value: value,
        coordinate: coordinate,
    }
}

Defining the Type as a slice

type HorizontalMatrix [][]datastructures.MatrixElement

Creating an instance of the new HorizonatlMatrix

func CreateHorizontalMatrix(rows int, columns int) HorizontalMatrix {
    horzMatrix := make([][]matrix.LocatableElement, rows)
    for i := 0; i < rows; i++ {
        horzMatrix[i] = make([]matrix.LocatableElement, columns)
    }
    return horzMatrix;
}

cannot use horzMatrix (type [][]matrix.LocatableElement) as type HorizontalMatrix in return argument

You can't neither cast []ConcreteTypes([]Interfaces) nor assert []Interfaces.([]ConcreteTypes) nevertheless ConcreteTypes implements Interfaces. You should either define container

type Matrix interface{
    GetElem(abs, ord int) MatrixElement 
}

and satisfy it for HorizontalMatrix or make matrix as []interface

horzMatrix := make([][]matrix.MatrixElement, rows)
horzMatrix[i] = make([]matrix.MatrixElement, columns)

and than populate it with concrete type LocatableElement