Skip to content

Instantly share code, notes, and snippets.

@RuedigerMoeller
Last active August 29, 2015 14:15
Show Gist options
  • Save RuedigerMoeller/7f31f246b0adb5c80a00 to your computer and use it in GitHub Desktop.
Save RuedigerMoeller/7f31f246b0adb5c80a00 to your computer and use it in GitHub Desktop.
abstract class ByteStream { .. }
class SomeClass {
void someMethod() {
this.getStream().writeByte(13); // call on interface or abstract class
}
ByteStream getStream() { .. }
}
// later in code
// does this avoid dynamic dispatch inside "SomeClass:someMethod" ?
SomeClass clsA = new SomeClass() {
ConcreteByteStream getStream() { .. }
};
SomeClass clsB = new SomeClass() {
OtherConcreteByteStream getStream() { .. }
};
@shipilev
Copy link

Not very sure. It definitely does not work when you compile SomeClass::someMethod in isolation. It probably does not also work when you compile SomeClass_anonymous1::someMethod, because the type profile is probably bound to the callsite in SomeClass::someMethod. You just have to check it yourself :)

@RuedigerMoeller
Copy link
Author

:-) i will some day, thanks for your statement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment