简体   繁体   中英

How to pass enum type to lambda

I've got a this function interface:

public static interface RotationDirectionCorectorGetter<MountingLocation extends Enum<MountingLocation>> {
    public Map<MountingLocation, Boolean> getModuleRotationDirectionCorrections(Map<MountingLocation, ModuleRotationVectors> rotationDirections);
}

Now i'd like to create an instance of it with a function that looks like this:

public static <MountingLocation extends Enum<MountingLocation>> Map<MountingLocation, Boolean> getModuleRotaionDirectionCorrections(
        Map<MountingLocation, ModuleRotationVectors> rotationDirections, boolean isRobotRotating) {
}

My first try was this, MountingLocations is an enum that exist localy in the same class:

RotationDirectionCorectorGetter<MountingLocations> directionCorectorGetter = (Map<MountingLocations, ModuleRotationVectors> rotationDirections) -> getModuleRotaionDirectionCorrections<MountingLocations>(rotationDirections);

Eventualy this doesn't work, vscode sais:

getModuleRotaionDirectionCorrections cannot be resolved or is not a field

What would be the correct syntax to do this or is this not even posible?

I made just a dum mistake i didn't remamber that the function also takes a boolean and not just a map. For general to this question, you don't have to specify the generic in the function that you're calling in the lambda so the solution looks like this:

RotationDirectionCorectorGetter<MountingLocations> directionCorectorGetter = (Map<MountingLocations, ModuleRotationVectors> rotationDirections) -> getModuleRotaionDirectionCorrections(rotationDirections, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM