Foo.Of{Int,Long,Double} naming convention
Doug Lea
dl at cs.oswego.edu
Mon Dec 24 04:27:34 PST 2012
On 12/23/12 12:44, Brian Goetz wrote:
> For types that have primitive specializations that are subtypes of the base type
> (e.g., MutableReducer), we've been converging on a naming convention that puts
> the subtypes as nested interfaces. For example:
>
> interface MutableReducer<T,R> {
>
> // reducer methods
>
> interface OfInt<R> extends MutableReducer<Integer,R> { ... }
> interface OfLong<R> extends MutableReducer<Integer,R> { ... }
> }
>
>
> Are we OK with this convention?
I'm not positive that it will hold up well without further
conventions, since it encounters the same overload/box issues
that led to different conventions for plain function types.
Consider using this for Function:
interface Function<A,R> {
R apply (A a);
interface OfInt extends Function<A, Integer> {
interface Function<A> {
int apply(A a); // nope
}
}
}
Which didn't quite work. One way out was equivalent to:
interface Function<A,R> {
R apply (A a);
interface OfInt extends Function<A, Integer> {
interface Function<A> {
default Integer apply(A a) { return applyAsInt(a); }
int applyAsInt(A a);
}
}
}
Which is itself a little fragile. The current versions
of Function etc don't bother to declare any subtyping.
But if it is the best we can do, the "asInt" ought to be
appended to all similar methods in ofInt interfaces?
-Doug
More information about the lambda-libs-spec-observers
mailing list