1

I was wondering if the "bridge" keyword on the JVM has any concrete purpose other than tagging a method as special? I'm asking this as opposed to "abstract" or "protected", which actually will directly influence the way the rest of your code is interpreted or functions.

Thanks

devoured elysium
  • 101,373
  • 131
  • 340
  • 557

1 Answers1

4

bridge isn't a keyword. It is used to tag synthetic methods used to implement generics and co-variant return types. It doesn't have much impact on performance and doesn't even appear in the call stack at runtime.

From http://www.docjar.com/html/api/java/lang/reflect/Modifier.java.html

/**
 * The {@code int} value representing the {@code volatile}
 * modifier.
 */
public static final int VOLATILE         = 0x00000040;

// Bits not (yet) exposed in the public API either because they
// have different meanings for fields and methods and there is no
// way to distinguish between the two in this class, or because
// they are not Java programming language keywords
static final int BRIDGE    = 0x00000040;
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Hmm.. it is found on ASM's Opcode list, but I'm not sure it is just an alias for a combination of other opcodes? http://asm.ow2.org/asm40/javadoc/user/constant-values.html#org.objectweb.asm.Opcodes.ACC_BRIDGE . Actually being 64 I'd dare say it is not a combination of other opcodes. – devoured elysium Jul 04 '12 at 17:54
  • "ACC_BRIDGE 0x0040 A bridge method, generated by the compiler." @ http://docs.oracle.com/javase/specs/jvms/se7/jvms7.pdf – devoured elysium Jul 04 '12 at 17:57
  • So, it actually IS a keyword. – devoured elysium Jul 04 '12 at 18:00
  • http://en.wikipedia.org/wiki/List_of_Java_keywords and http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html – Peter Lawrey Jul 04 '12 at 18:01
  • The JVM doesn't define any keywords. – Peter Lawrey Jul 04 '12 at 18:05
  • Anyway, you didn't even answer the question at all. Are there any *concrete* differences between a tagged or nontagged bridge method? – devoured elysium Jul 04 '12 at 19:09
  • "It doesn't have much impact on performance and doesn't even appear in the call stack at runtime." What sort of different are you looking for? – Peter Lawrey Jul 04 '12 at 19:10
  • As the JVM optimises small method away. Even inlined and synthetic methods normally appear in the stack track, but these synthetic methods don't. – Peter Lawrey Jul 04 '12 at 19:13