Re: operator overloading
- From: Joshua Cranmer <Pidgeot18@xxxxxxxxxxxxxxx>
- Date: Fri, 09 May 2008 21:28:14 GMT
Owen Jacobson wrote:
On May 8, 8:10 pm, Tom Anderson <t...@xxxxxxxxxxxxxxx> wrote:Also, can i declare:
public class Vector implements Multipliable<double, Vector>,
Multipliable<Vector, double>, Multipliable<Matrix, Vector>
?
No, as double is not a reference type; no, as you can't implement an
interface more than once and all those generic specializations are
really the same interface. The former can be worked around with the
language as-is; the latter cannot. Allowing that would involve
changing the way method overloads are resolved, or adding rules to
forbid implementing both Multipliable<Double, Vector> and
Multipliable<Vector, Vector> - as it stands, you can't provide both
public Double multiply (Vector) and public Vector multiply (Vector) in
the same class, because the only distinction is the return type.
Multipliable<Double, Vector> would essentially provide the same service as Multipliable<double, Vector> thanks to auto-(un)boxing.
Also (as the one who posted with this proposal), the idea of LHS operator overloading cannot be satisfactorily be solved in this manner; I've been racking my brains for a solution and have found known (more discussion in my earlier thread 'Java 7 Features').
This would be Tom's proposed declaration (I believe he munged the syntax), then:
public class Vector implements Multipliable<Double, Vector> {
}
public class Matrix implements Multipliable<Double, Matrix>,
Multipliable<Matrix, Matrix>, Multipliable<Vector, Vector> {
}
Unfortunately, to do so would still require modification such that a class can implement the same generic interface multiple times with different generic arguments--i.e., reification of generics.
--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.
- References:
- operator overloading
- From: josh
- Re: operator overloading
- From: Leonard Milcin
- Re: operator overloading
- From: josh
- Re: operator overloading
- From: Leonard Milcin
- Re: operator overloading
- From: Tom Anderson
- Re: operator overloading
- From: Owen Jacobson
- Re: operator overloading
- From: Tom Anderson
- Re: operator overloading
- From: Owen Jacobson
- Re: operator overloading
- From: Tom Anderson
- Re: operator overloading
- From: Owen Jacobson
- operator overloading
- Prev by Date: Re: java.text.DecimalFormat problems
- Next by Date: Re: java.text.DecimalFormat problems
- Previous by thread: Re: operator overloading
- Next by thread: Re: operator overloading
- Index(es):
Relevant Pages
|