I try to obtain an object from the Person class (class already created) but I want to obtain it with the Optional interface, because the object could or could not be found in a Set of People. The method would be like this:
public Optional<Persona> getPersona(Persona pe)
{
Optional<Persona> user = Optional.ofNullable(null);
Predicate<Persona> ver = umano ->
{
boolean b = false;
for(Persona i: personas) // personas es el Set de personas ya creado
{
if(i.equals(pe))
b = true;
}
return b;
};
user.filter(ver);
if(user.isPresent())
user.get();
return user;
}