Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

13.6. Java Expressions


Expand
Table 13.1. Java Expressions
Capability Example
You can use any Java expression that returns a boolean as a constraint inside the parentheses of a pattern. Java expressions can be mixed with other expression enhancements, such as property access.
Person( age == 50 )
Copy to Clipboard Toggle word wrap
You can change the evaluation priority by using parentheses, as in any logic or mathematical expression.
Person( age > 100 && ( age % 10 == 0 ) )
Copy to Clipboard Toggle word wrap
You can reuse Java methods.
Person( Math.round( weight / ( height * height ) ) < 25.0 )
Copy to Clipboard Toggle word wrap
Type coercion is always attempted if the field and the value are of different types; exceptions will be thrown if a bad coercion is attempted.
Person( age == "10" ) // "10" is coerced to 10
Copy to Clipboard Toggle word wrap

Warning

Methods must not change the state of the object in a way that may affect the rules. Any method executed on a fact in the LHS should be a read only method.

Warning

The state of a fact should not change between rule invocations (unless those facts are marked as updated to the working memory on every change):
Person( System.currentTimeMillis() % 1000 == 0 ) // Do NOT do this
Copy to Clipboard Toggle word wrap

Important

All operators have normal Java semantics except for == and !=.
The == operator has null-safe equals() semantics:
// Similar to: java.util.Objects.equals(person.getFirstName(), "John")
// so (because "John" is not null) similar to:
// "John".equals(person.getFirstName())
Person( firstName == "John" )
Copy to Clipboard Toggle word wrap
The != operator has null-safe !equals() semantics:
// Similar to: !java.util.Objects.equals(person.getFirstName(), "John")
Person( firstName != "John" )
Copy to Clipboard Toggle word wrap
Nach oben
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2025 Red Hat