JDK 7: Proposition 10 : Le même type
Aujourd'hui :
Code:
1 2 3 4 5 6 7 8 9
|
class Buffer {
Buffer flip() {
}
Buffer position(int newPos) {
}
Buffer limit(int newLimit) {
}
}
class ByteBuffer extends Buffer {
ByteBuffer put(byte data) {
}
} |
Code:
1 2 3 4
| ByteBuffer buf = ...;
buf.flip().position(12); // OK
buf.flip().put(12); // Error
((ByteBuffer)(buf.flip())).put(12); // Obliged to cast |
Demain :
Proposition 1 :
Code:
1 2 3 4 5 6 7 8 9
|
class Buffer {
this flip() { … }
this position(int newPos) { … }
this limit(int newLimit) { … }
}
class ByteBuffer extends Buffer {
this put(byte data) { … }
} |
Proposition 2 :
Code:
1 2 3 4 5 6 7 8 9
|
class Buffer {
This flip() {
}
This position(int newPos) {
}
This limit(int newLimit) {
}
}
class ByteBuffer extends Buffer {
This put(byte data) {
}
} |
Code:
1 2 3
| ByteBuffer buf = ...;
buf.flip().position(12); // OK
buf.flip().put(12); // OK |