Skip to content

Commit

Permalink
add cast() method to Expression
Browse files Browse the repository at this point in the history
See #395
  • Loading branch information
gavinking authored and lukasj committed Aug 10, 2023
1 parent 21757fd commit 7023d0e
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions api/src/main/java/jakarta/persistence/criteria/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,29 @@ public interface Expression<T> extends Selection<T> {
/**
* Perform a typecast upon the expression, returning a new
* expression object.
* This method does not cause type conversion:
* the runtime type is not changed.
* Warning: may result in a runtime failure.
* Unlike {@link #cast(Class)}, this method does not cause
* type conversion: the runtime type is not changed.
* <p><em>Warning: may result in a runtime failure.</em>
* @param type intended type of the expression
* @return new expression of the given type
* @see #cast(Class)
*/
<X> Expression<X> as(Class<X> type);

/**
* Cast this expression to the specified type, returning a
* new expression object.
* Unlike {@link #as(Class)}, this method <em>does</em>
* result in a runtime type conversion.
* <p><em>Providers are required to support casting
* scalar expressions to {@link String}, and
* {@code String} expressions to {@link Integer},
* {@link Long}, {@link Float}, and {@link Double}.
* Support for typecasts between other basic types is
* not required.</em>
* @param type a basic type
* @return a scalar expression of the given basic type
* @since 3.2
*/
<X> Expression<X> cast(Class<X> type);
}

0 comments on commit 7023d0e

Please sign in to comment.