我有一个课程,即下面提供的@Injectable()
export class Globals {
public baseURL:string;
public loginURL:string;
public proxyURL:string;
public servicesURL:string;
constructor(platformLocation: PlatformLocation) {
this.baseURL = (platformLocation as any).location.href;
this.loginURL = this.baseURL + 'rest/login';
this.proxyURL = this.baseURL + 'rest/proxy';
this.servicesURL = this.baseURL + 'rest/serviceRegistry';
}
}
,
OrderProviderData
我想设置public class OrderProviderData {
public enum TradingInterface {CX_CLIENT, CX_SERVER, CX_ADMIN, CX_ENGINE}
private boolean easyTrade = false;
private OrderPreSelect order;
private String[] event;
public OrderPreSelect getOrder() {
return order;
}
public void setOrder(OrderPreSelect order) {
this.order = order;
}
public String[] getEvent() {
return event;
}
public void setEvent(String[] event) {
this.event = event;
}
}
实例的值
基于某些条件的OrderProviderData
方法。
receiveEvent
如何正确编写?我也愿意提供更好的建议。
答案 0 :(得分:1)
将枚举作为字段添加到您的班级。您只是定义枚举本身。 (也需要吸气剂和固定剂)
公共类OrderProviderData {
public enum TradingInterface {CX_CLIENT, CX_SERVER, CX_ADMIN, CX_ENGINE}
private boolean easyTrade = false;
private TradingInterface tradingInterface;
private OrderPreSelect order;
private String[] event;
public OrderPreSelect getOrder() {
return order;
}
public void setOrder(OrderPreSelect order) {
this.order = order;
}
public String[] getEvent() {
return event;
}
public void setEvent(String[] event) {
this.event = event;
}
public TradingInterface getTradingInterface() {
return tradingInterface;
}
public void setTradingInterface(TradingInterface tradingInterface) {
this.tradingInterface = tradingInterface;
}
}
然后您可以switch
查看案例(这是枚举的值)。您无法在switch
和第一case
@Override
public final Object receiveEvent() throws Exception {
Server f = new Server();
switch (f.getInf()) {
case CX_CLIENT:
// set
break; // optional
case CX_SERVER:
// set
break; // optional
default:
// some code
}
}