我正在尝试将以下Swift 4.1.2代码转换为Java 1.5或更高版本。我嵌套了包含各种结构的枚举。import UIKitenum CreateOrder{ enum FormatUseByDate { struct Request { var date: Date } struct Response { var date: Date } struct ViewModel { var date: String } }}Java 不支持struct关键字。但是,struct相当于上述结构之一的可能是:class Request{ public Date date;}我已经多次尝试创建嵌套的枚举并引用等效的结构。如:import java.util.Date;interface Usecase {}class Response implements Usecase { public Date date;}class Request implements Usecase { public Date date;}class ViewModel implements Usecase { String date;}public class EnumDemo { enum CreateOrder { FORMATUSEBYDATE; enum FormatUseByDate { REQUEST(new Request()), RESPONSE(new Response()), VIEWMODEL(new ViewModel()); Usecase usecase; FormatUseByDate(Request req) { this.usecase = req; } FormatUseByDate(Response res) { this.usecase = res; } FormatUseByDate(ViewModel vm) { this.usecase = vm; } } } public static void main(String[] args) { System.out.println(CreateOrder.FormatUseByDate.REQUEST); // Attempt at referencing the REQUEST struct equivalent }}但是,我不确定如何从枚举中引用class要用作struct等效项的 ,以及它们是否可以在枚举的主体中定义。
添加回答
举报
0/150
提交
取消