Reputation: 1581
I am trying to write a scripted AI; and ran into this problem. In the following base class, how can I tell x
that it can just as well expect a write
reference?
class Node <T0, T1, T2> {
Node() {
// More missing non-relevance.
}
T0 write(T1 x) {
T0.write(x.read());
}
T0 write(T2 x) {
T0.write(x.read());
}
}
EDIT: Here is the error:
Parser.java:181: cannot find symbol
symbol : method read()
location: class java.lang.Object
P.S. Or should I just do this in C++ function pointers.
Upvotes: 0
Views: 54
Reputation: 6523
In java you would need an Interface/class that has the read method. You ether use a standard one (perhaps x is an OutputStream
implementation?). Otherwise you would create your own interface. (Had to interpret a lot, but perhaps the code below is helpful)
class Node <T0 extends OutputStream, T1 extends InputStream> {
T0 to;
Node(T0 to) {
this.to = to;
}
T0 write(T1 x) throws IOException {
to.write(x.read());
return to;
}
}
Upvotes: 4