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
PS Or should I just do this in C++ function pointers.
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;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.