I keep getting error on RandomUniformGenerator method that made the tile attribute so that it corresponds to the list of tiles of the requested colors but it tell me provided UniformTile instead of List , but List is abstract and can't be instantiated. need help with this one :/
package model;
import javafx.scene.paint.Color;
import java.util.List;
import java.util.Random;
public class RandomUniformTileGenerator implements TileGenerator{
private final List<Tile> tiles;
private final Random randomGenerator;
public RandomUniformTileGenerator(List<Color> colors, Random randomGenerator){
this.tiles = new UniformTile(new ColoredSide(colors.get(colors.size()))) ;
this.randomGenerator = randomGenerator;
}
public Tile nextTile(Square square){
return this.tiles.get(randomGenerator.nextInt(tiles.size()));
}
}
// Tile generator
package model;
public interface TileGenerator {
Tile nextTile(Square square);
}
// UniformTile
package model;
public class UniformTile implements Tile{
private final Side side;
public UniformTile(Side side) {
this.side = side;
}
public Side side(CardinalDirection direction){
return side;
}
}
// ColorSide
package model;
import javafx.scene.paint.Color;
import model.Side;
public class ColoredSide implements Side {
private final Color color;
public ColoredSide(Color color){
this.color = color;
}
public Color color() {
return color;
}
}
// Side
package model;
import javafx.scene.paint.Color;
import java.util.List;
public interface Side {
Color color();
}
List
is just a interface and specifies the methods a class must implement. A implementation of List
would be ArrayList
or LinkedList
. So in your example you would want something like:
private final List<Tile> tiles = new ArrayList()<>;
We initialize the variable tiles
as ArrayList
, but the actual implementation is hidden behind the List
declaration.
Instead of writing List<Tile>
= UniformTile
you probably want to add
your tile to the List of tiles
.
tiles.add(new UniformTile(new ColoredSide(colors.get(colors.size()))));
@Togo_Yan 如果您有任何其他问题,请给我发电子邮件
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.