1

我试图声明很多枚举,但是由于某种原因,其中一个是错误的,我真的不明白为什么。

我的声明:

public class Enums {

    public enum MainObjectType {
        Plan = 0
                StationEntrance = 1
                StationConcourse_Hall = 2
                StationPlatform = 3
                StationStairs = 4
                StationEscalator = 5
                StationLift = 6
                StationRamp = 7
                StationSubway = 8
                StationTicket_Gates = 9
                StationOther = 12
                StationCar_Park = 13
                StationToilets = 14
                StationDoors = 15
                StationTravelator = 16
                StationLevel = 17
                StationMulti_stairs = 19
                StationSupervisor = 20
                StationInformation_Stand = 24
                StationTicket_Office = 28
                StationTravel_Info_Office = 30
                StationBabyChange = 50
                StationAccessibleToilets = 57
                StationTicket_Counter = 58
                StationDropOffPoint = 59
                StationStartPoint = 60
                StationToiletArea = 61

                StationTaxi = 250
                StationTaxiDropOffPoint = 259

                CarPark = 501
                Circulation = 502
                Internal_Doors = 503
                Surfaces = 504
                Toilets = 505
                Seating = 506
                Counters_Service_Desks = 507
                Telephones = 508
                Signage = 509
                Lighting = 510

                Acoustics = 511
                Drop_off = 513
                Routes = 514
                Reception = 515
                Consultation_area = 516
                Creche = 518
                Means_of_escape = 519
                Ramp = 523
                Steps = 524
                PassengerLift = 525
                PlatformLift = 526
                SwimmingPool = 527
                ChangingRoom = 528
                VendingMachine = 529
                CashMachine = 530
                Entrance = 531
                Room = 532
                AccessibleWC = 533
                Consultation_Room = 535
                TransportTypes = 536
                Escalator = 537
                Intercomm = 538
                Other = 539
                CorridorRoom = 540
                Approach = 586
                WheelChairStairLift = 587
                MultiRamp = 588
                BusStands = 591
                BusStop = 592
                Level = 594
                FloorPlan = 1001
                WayPoint = 1003
                RoutingArrow = 1004
                Poster = 1005
                GlobalArea = 1007

                ManagersQuestions = 2000
                Knowledgebase = 2001
                SeatingBlock = 2002

                FireExtinguisher = 2006

                HS_StatutoryComplianceDocs = 3003
                HS_WorkplaceQuestions = 3004
                HS_Findings = 3005
                HS_Verification = 3006
                HS_Assessor_Notes = 3008

                FR_Limitations = 3001
                FR_PolicyReview = 3002
                FR_Verification = 3021
                FR_Findings = 3022
                FR_Policies = 3024
                FR_AlarmSystem = 3056
                FR_Assessor_Notes = 3007

                GEN_BuildingQuestions = 3023


                NPM_PolicyReview = 3550
                NPM_ManagerQuestions = 3552
                NPM_Policies = 3551
                NPM_Verification = 3553

                NPM_Findings = 3554
                NPM_Assessor_Notes = 3555
                AssetItem = 3200


                FR_MajorIssues = 3562
                HS_MajorIssues = 3563
                NPM_MajorIssues = 3564
    }


}

错误说:语法错误,插入}来完成类体

在此处输入图像描述

4

2 回答 2

3

枚举的元素需要用逗号分隔,并且您设置每个元素的值的语法不正确。

首先,您需要使用正确的语法来设置值。语法应该是EnumValue(value)您有一个私有构造函数的地方,该构造函数采用您将枚举元素设置为的类型。在这种情况下,您private MainObjectType(int value)的枚举中需要一个构造函数。您还需要用逗号分隔每个元素。

查看枚举类型的 Java 教程以获取一些示例。

于 2012-09-17T12:49:29.713 回答
3

您的语法无效。你可以写:

public enum MainObjectType  {
    StationEntrance,
    StationConcourse_Hall,
    StationPlatform,
    StationStairs,
    // ...
    NPM_MajorIssues;        
}

但这会丢失编号。或者您可以使用以下语法提供一个数字:

public enum MainObjectType  {
    StationEntrance(1),
    StationConcourse_Hall(2),
    StationPlatform(3),
    StationStairs(4),
    // ...
    NPM_MajorIssues(3564);        

    private final int id;
    private MainObjectType(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }
}

然后你可以写:

int id = MainObjectType.StationEntrance.getId(); //id = 1
于 2012-09-17T12:49:44.470 回答