POO-ITBA / 2024_01

Consultas 1C 2024
0 stars 0 forks source link

Parcial 2024 1C - Ejercicio 3 #35

Closed lmoliveto closed 1 month ago

lmoliveto commented 2 months ago

Hola! Está bien esta forma de crear el Predicate? new Predicate<>(c -> !c.isOccupied() && c.getAirline().startsWith("A"))

fmeola commented 2 months ago

Hola @lmoliveto

No, estás mezclando la sintaxis de una clase anónima (new Predicate) con la de expresión lambda. Las siguientes son válidas:

Predicate<Counter> idleAndStartsWithA = checkInCounter -> !checkInCounter.isCheckIn() && checkInCounter.getAirline().startsWith("A");
Predicate<Counter> idleAndStartsWithA = (checkInCounter) -> {
    return !checkInCounter.isCheckIn() && checkInCounter.getAirline().startsWith("A");
};
Predicate<Counter> idleAndStartsWithA = new Predicate<Counter>() {
    @Override
    public boolean test(Counter checkInCounter) {
        return !checkInCounter.isCheckIn() && checkInCounter.getAirline().startsWith("A");
    }
};
lmoliveto commented 2 months ago

Genial. En la última opción, hace falta aclarar el tipo de dato generic cuando hago new Predicate<>(){...}?

fmeola commented 2 months ago

No, es verdad, podés utilizar el operador diamante