user11731595:
私はにより確認することが何リットルオブジェクトを作成する必要があるinstanceof
キーワードを。
お気に入り
public class Example {
private int create(GUIItemType type){
if(type instanceof GUIItemTypeCommand){
return 0;
} else if (type instanceof GUIItemTypeSend){
return 1;
} else {
return 2;
}
}
}
Whay私はそれを作成するために使用する必要が?GUIItemTypeCommandクラス必見GUIItemTypeクラスを拡張しますか?GUIItemTypeクラスは、抽象的でなければなりませんか?
アービンド・クマールのAvinash:
あなたは、作成することができますGUIItemType
ようinterface
、次に作るGUIItemTypeCommand
とGUIItemTypeSend
それを実装します。
interface GUIItemType {
// default methods, abstract methods, public static final variables
}
class GUIItemTypeCommand implements GUIItemType {
}
class GUIItemTypeSend implements GUIItemType {
}