problems about generics

Hi, I'm new to this forum.

I've the following problem:

public interface Field<T> {

T getOne();

T getZero();

T plus(T x);

T times(T x);

}

public class DoubleField implements Field<Double> {

public DoubleField(double d) {

this.d = d;

}

public Double getOne() {

return 1.0;

}

public Double getZero() {

return 0.0;

}

public Double plus(Double x) {

return d + x.d;

}

public Double times(Double x) {

return d * x.d;

}

private double d;

}

Now I must implement a generic class Polynomial that rispects the following uses case :

DoubleField[ ] d = { new DoubleField(4), ...};

Polynomial<DoubleField> p = new Polynomial<DoubleField>(d);

System.out.println(p.eval(new DoubleField(3));

So...

public class Polynomial< I don't know > {

public Polynomial(//I don't hnow) {

}

// I don't think this type is right !

public T eval(Field<T> x) {

T val = x.getZero();

T pow = x.getOne();

for(int i = 0; i < coef.length; i++){

val.plus(coef.times(pow));

pow = x.times(pow);

}

return val;

}

private //Type [ ] coef;

}

Can you help me, please ?

[1350 byte] By [mcp01a] at [2007-11-27 10:45:28]
# 1

Please post your question on the generics forum:

http://forum.java.sun.com/forum.jspa?forumID=316

gymma at 2007-7-28 20:13:08 > top of Java-index,Java Essentials,New To Java...
# 2

geeze, and I never even knew this site had a generics forum!

petes1234a at 2007-7-28 20:13:08 > top of Java-index,Java Essentials,New To Java...