user11731595:
Eu preciso criar um objetos que l pode para verificação por instanceof
palavra-chave.
Gostar
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 eu preciso usar para criar esse? GUIItemTypeCommand classe deve estende a classe GUIItemType? classe GUIItemType deve ser abstrato?
Arvind Kumar Avinash:
Você pode criar GUIItemType
como um interface
e depois fazer GUIItemTypeCommand
e GUIItemTypeSend
implementá-lo.
interface GUIItemType {
// default methods, abstract methods, public static final variables
}
class GUIItemTypeCommand implements GUIItemType {
}
class GUIItemTypeSend implements GUIItemType {
}