```model.searchTextProperty().addListener((obs, ol...
# getting-started
t
Copy code
model.searchTextProperty().addListener((obs, old, val) -> {
    var empty = val == null || val.isBlank();
    pseudoClassStateChanged(FILTERED, !empty);
    navMenu.setPredicate(empty ? PREDICATE_ANY : region -> region instanceof NavLink link && link.matches(val));
});


public void setPredicate(Predicate<Region> predicate) {
    content.setPredicate(predicate);
}
I have such a code block, how can I translate it to kotlin language?
s
t
I know but this translates the code incorrectly
s
strange, I've never had problems with it. It's normal that you have to clean up the generated Kotlin code (mostly the nullability) afterwards, but if it produces incorrect code, that's clearly a bug. Maybe it's because one of your parameters is called
val
and that's a keyword in Kotlin?? It should look something like this: • first code snippet
Copy code
model.searchTextProperty().addListener( Listener { obs, old, value ->  // you might need to add the types!? Also I assume the the type of the Listener that addListener takes is "Listener", adapt if different
    val isEmpty = value.isNullOrBlank()
    pseudoClasStateChanged(FILTERED, !isEmpty)
    navMenu.predicate = if(isEmpty) {
        PREDICATE_ANY
    } else {
        Predicate { region: Region -> region is NavLink && region.matches(value) }  // region is smart-casted to NavLink for the second part of the expression
    }
})
• second part, the setter
Copy code
var predicate: Predicate<Region>
    set(regionPredicate) {
        content.predicate = regionPredicate
    }
t
Thank you very much I will try this 🙂