dartwith-statementlanguage-construct

Can I use an implicit class name in Dart?


Is there any way to avoid having to explicitly specify a class name in Dart, when using it multiple times?

Let's say I have something like

class VehicleType{
    static const int BICYCLE    = 0;
    static const int CAR        = 1;
    static const int BUS        = 2;

    // ... etc ...      
}



class VehicleGroup{ 
        static List<int> YEARLY_INSPECTION =[ 
            VehicleType.CAR,
            VehicleType.BUS
        ];

        static List<int> REQUIRES_LICENSE =[
            VehicleType.CAR,
            VehicleType.BUS
        ];

        static List<int> NO_MINIMUM_AGE =[
            VehicleType.BICYCLE
        ];

        // ... etc ...
}

Is there any way I can avoid having to explicitly specify VehicleType. for every member in a group? I'm thinking something like the with statement that is available in some other languages like Javascript, Visual Basic and Object Pascal .


Solution

  • I don't believe there's any shorter way of specifying that. The class name (or you could have used an enum here if you didn't care about values) scopes the identifiers so that you won't have collisions.