Usando classes abstratas \ Interfaces

user11731595:

Eu preciso criar um objetos que l pode para verificação por instanceofpalavra-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 GUIItemTypecomo um interfacee depois fazer GUIItemTypeCommande GUIItemTypeSendimplementá-lo.

interface GUIItemType {
    // default methods, abstract methods, public static final variables
}

class GUIItemTypeCommand implements GUIItemType {

}

class GUIItemTypeSend implements GUIItemType {

}

Acho que você gosta

Origin http://10.200.1.11:23101/article/api/json?id=394049&siteId=1
Recomendado
Clasificación