Re:Bytecode features not available in the Java language
by quotemstr on Friday April 17, 2015 @04:23PM
(#9396982)
You can define two methods that differ only by return type. That's how covariant returns work. Check the javap output and recoil in horror.
[ Parent
| on HN ]
Re:Bytecode features not available in the Java language
by peeters on Friday April 17, 2015 @04:35PM
(#9397057)
True. One of them is a bridge method.
Here's an example:
class CovariantReturn extends CovariantReturnBase {
public Integer produce() {
return 5;
}
}
class CovariantReturnBase {
public Number produce() {
return 4.5;
}
}
And the relevant javap output for CovariantReturn: public java.lang.Integer produce();
flags: ACC_PUBLIC
Code:
...
public java.lang.Number produce();
flags: ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC
Code:
...