-
Notifications
You must be signed in to change notification settings - Fork 869
-
Notifications
You must be signed in to change notification settings - Fork 869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polymorphic CaseBuilder.Initial.then #702
Comments
@dmitrygusev Could you comment if this change is sufficient #703 ? The |
No, this doesn't help much. Here's what I did: I have a method that builds case expression based on some predefined condition set, but "then"-part of that case expression may differ: interface ReminderExpression<T> {
Expression<T> then(QReminder reminder);
}
QReminder reminder1 = new QReminder("reminder1");
QReminder reminder2 = new QReminder("reminder2");
QReminder reminder3 = new QReminder("reminder3");
<T> Expression<T> getReminderCase(ReminderExpression<T> thenExpr) {
return new BetterCaseBuilder()
.when(CONDITION1)
.then2(thenExpr.then(reminder1))
.when(CONDITION2)
.then(thenExpr.then(reminder2))
.otherwise(thenExpr.then(reminder3));
} Then I have few another methods that use this method to build actual expression, like: DateExpression<Date> getReminderDateCase() {
return (DateExpression<Date>) getReminderCase(new ReminderExpression<Date>() {
@Override public Expression<Date> then(QReminder reminder) {
return dateAdd(invoice.dueOn, reminder.offsetInDays);
}
});
} As you mentioned, I tried solution from #703 and this example worked, but I have another method that builds actual expression and returns interface ReminderExpression<T extends Comparable<T>> {
ComparableExpression<T> then(QReminder reminder);
}
NumberExpression<Byte> getReminderOrderNumberCase() {
return (NumberExpression<Byte>) getReminderCase(new ReminderExpression<Byte>() {
@Override public ComparableExpression<Byte> then(QReminder reminder) {
// COMPILE ERROR:
// Type mismatch: cannot convert
// from NumberPath<Byte> to ComparableExpression<Byte>
return reminder.orderNumber;
}
});
} |
@dmitrygusev I used now your then2 code in the pull request. Could you take a look? It should work with a single method, since all the other Expression types are subclasses of SimpleExpression. |
yep, works good now, thanks |
Ok, good. Are these replacements also ok for you?
|
For me, yes. All my tests passed with changes from #703. |
Released in 3.3.3 |
Using variable of general type (like
Expression<T>
) innew CaseBuilder().when().then(HERE)
will always call version ofthen
with this signature:which means you will get
SimpleOperation
in response and you can't use it in "order by" clauses and other methods that require concrete type because it can't be cast fromSimpleOperation
.This could be solved by providing polymorphic version of "then" that will decide which overload to invoke at runtime based on type of expression, here's an example of how this method may look like:
The text was updated successfully, but these errors were encountered: