I'd like to be able to require that you at least can only call greatest and

least on something that was Comparable, but unfortunately, the numeric type's
only shared supertype is Number and that is not comparable.

If I require Number, then you can't do greatest(timestamp, timestamp), and if I
require Comparable, then you can't do greatest(int, double) because the
compiler can't unify those types to something that is Comparable.

I could require that you only compare apples with apples (i.e. greatest(int,
int) or greatest(double, double)), but databases will happily compare
greatest(int, double) and people are going to want to do that. I could
introduce some sort of numeric conversion expressions, but I think that's
getting too deeply into the realm of type safety for type safety's sake.
This commit is contained in:
Michael Bayne
2010-12-09 00:21:44 +00:00
parent b01eaef2d8
commit f629b267ba
2 changed files with 8 additions and 8 deletions
@@ -127,8 +127,8 @@ public class Funcs
/**
* Creates an expression that evaluates to the largest of the given expressions.
*/
public static <T extends Number> FluentExp<T> greatest (SQLExpression<? extends T> arg1,
SQLExpression<? extends T> arg2)
public static <T> FluentExp<T> greatest (SQLExpression<? extends T> arg1,
SQLExpression<? extends T> arg2)
{
return new Greatest<T>(arg1, arg2);
}
@@ -136,7 +136,7 @@ public class Funcs
/**
* Creates an expression that evaluates to the largest of the given expressions.
*/
public static <T extends Number> FluentExp<T> greatest (SQLExpression<? extends T>... args)
public static <T> FluentExp<T> greatest (SQLExpression<? extends T>... args)
{
return new Greatest<T>(args);
}
@@ -144,8 +144,8 @@ public class Funcs
/**
* Creates an expression that evaluates to the smallest of the given expressions.
*/
public static <T extends Number> FluentExp<T> least (SQLExpression<? extends T> arg1,
SQLExpression<? extends T> arg2)
public static <T> FluentExp<T> least (SQLExpression<? extends T> arg1,
SQLExpression<? extends T> arg2)
{
return new Least<T>(arg1, arg2);
}
@@ -153,7 +153,7 @@ public class Funcs
/**
* Creates an expression that evaluates to the smallest of the given expressions.
*/
public static <T extends Number> FluentExp<T> least (SQLExpression<? extends T>... args)
public static <T> FluentExp<T> least (SQLExpression<? extends T>... args)
{
return new Least<T>(args);
}
@@ -41,7 +41,7 @@ public abstract class ConditionalFun
}
}
public static class Greatest<T extends Number> extends ManyArgFun<T> {
public static class Greatest<T> extends ManyArgFun<T> {
public Greatest (SQLExpression<? extends T>... args) {
super(args);
}
@@ -56,7 +56,7 @@ public abstract class ConditionalFun
}
}
public static class Least<T extends Number> extends ManyArgFun<T> {
public static class Least<T> extends ManyArgFun<T> {
public Least (SQLExpression<? extends T>... args) {
super(args);
}