Абстрактные статические методы в Java [закрыто]JAVA

Программисты JAVA общаются здесь
Anonymous
Абстрактные статические методы в Java [закрыто]

Сообщение Anonymous »

Недавно я работал над своим шахматным приложением на основе Java, где у меня был абстрактный Chessiece класс, немного похожий на это:

Код: Выделить всё

public abstract class ChessPiece {
// ... some common fields
public abstract ChessPositionCoorinate getChessPositionCoorinate();
public abstract Colour getColour();

/**
* Provides the name of the chess piece.
*/
public abstract String getName();
}
Я расширил этот класс на шахматные произведения, такие как King , Queen и другие. I mean, if a class King is extending the ChessPiece class, it still needs to override the getName() method, which is an object-level method, so it occupies memory in each instance of King.
Now, if we had the option to create an abstract static method like this:

Код: Выделить всё

public abstract class ChessPiece {
// ... some common fields
public abstract ChessPositionCoorinate getChessPositionCoorinate();
public abstract Colour getColour();

/**
* Provides the name of the chess piece.
*/
public static abstract String getName();
}
Тогда все подклассы могли бы переопределить его, и он не будет занимать дополнительную память, поскольку он будет находиться на уровне класса для каждого подкласса.>

Подробнее здесь: https://stackoverflow.com/questions/797 ... ds-in-java

Вернуться в «JAVA»