All Packages Class Hierarchy This Package Previous Next Index
The ChannelInput interface should be used to hold references to Channels when they are only going to be used for inputting data from. By using the ChannelInput interface any attempt to write to the Channel using the reference to a ChannelInput type will generate a compile time error. The following code fragment would not compile.
void doWrite(ChannelInput c, Object o) { c.write(o); // illegalThis interface should be used to pass Channels around where processes only require read access to the Channel.
The Object returned can be discarded or cast into the actual Class the reader process expects. If the reader can handle more than one type of Object (similar to tagged protocols in occam) if statements can be used to check the type of the Object before casting. If the Object returned is cast without checking the type of the Class first a ClassCastException will be thrown if the Object sent is of a different type.
void doRead(ChannelInput c) { c.read(); }
void doRead(ChannelInput c) { Boolean b = (Boolean)c.read(); // will cause a ClassCastException // if read does not return a Boolean }
void doRead(ChannelInput c) { Object o = c.read(); if (o instanceof Boolean) { System.out.println("Boolean: " + (Boolean)o); } else if (o instanceof Integer) { System.out.println("Integer: " + (Integer)o); } else { System.out.println("Unexpected Class: " + o); } }
public abstract Object read()
All Packages Class Hierarchy This Package Previous Next Index