Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.
ihandler
Unregistered
|
|
I am trying to do some mathematical constructions that do not appear to work. I think I am pushing this envelope too far but would like to understand what is wrong: Here is a simple parameterized interface:
public interface Ring<A> { public A plus(A a) throws RingException; public A minus(A a) throws RingException; public A times(A a) throws RingException; public A copy() throws RingException; }
and an attempt to create a generic way to extend any ring by i:
public class Gaussian<A extends Ring<A>> implements Ring<Gaussian<A>> { A real; A imaginary; /** Creates a new instance of Gaussian */ public Gaussian(A real, A imaginary) { this.real = real; this.imaginary = imaginary; } public A getReal() { return real; } public A getImaginary() { return imaginary; } public Gaussian<A> plus(Gaussian<A> b) throws RingException { return new Gaussian(real.plus(b.getReal()), imaginary.plus(b.getImaginary())); } public Gaussian<A> minus(Gaussian<A> b) throws RingException { A r = real.minus(b.getReal()); A i = imaginary.minus(b.getImaginary()); return new Gaussian(r, i); } public Gaussian<A> times(Gaussian b) throws RingException { A r = (A) real.times((A) b.getReal()).minus((A) imaginary.times((A) b.getImaginary())); A i = (A) imaginary.times((A) b.getReal().plus((A) real.times((A) b.getImaginary()))); return new Gaussian(r, i); } public Gaussian<A> copy() throws RingException { return new Gaussian((Ring<A>) real.copy(), (Ring<A>) imaginary.copy()); } }
Gaussian does compile but netbeans 4.0 still complains in the declaration that I have not defined a times correctly according to Ring<A>. Is netbeans off or am I??
Thanks Ivan ihandler@igc.org
|
Unregistered
|
|
This is prefectly ok. Must be issue with the Net beans.
Rajneesh Bhandari Thaparian
|
|
0 registered and 1 anonymous users are browsing this forum.
Moderator:
Print Topic
|
Forum Permissions
You cannot start new topics
You cannot reply to topics
HTML is disabled
UBBCode is enabled
|
Rating:
Topic views: 4895
|
|
|
|
|
|
Powered by UBB.threads™ 6.5.5