I got this question from javaBlackBelt.
Which of the following statements are true about bridge methods in Java 5?
They are synthetic
They are generated by the compiler
They are not necessary if the code does not use generics
The compiler rejects code that directly calls a bridge method
It is possible to call a bridge method using reflection
Explanation
Bridge methods are inserted by the compiler to ensure correct overriding. They are sometimes necessary when overriding generic types and they are necessary for covariant method return types. So bridge methods are not limited to code using generics. A bridge method is synthetic and cannot be called directly but it can be called using reflection. Of course they should not be called and doing so may result in error, e.g. a ClassCastException, when calling a bridge method with wrong parameter types.
Which of the following statements are true about bridge methods in Java 5?
They are synthetic
They are generated by the compiler
They are not necessary if the code does not use generics
The compiler rejects code that directly calls a bridge method
It is possible to call a bridge method using reflection
Explanation
Bridge methods are inserted by the compiler to ensure correct overriding. They are sometimes necessary when overriding generic types and they are necessary for covariant method return types. So bridge methods are not limited to code using generics. A bridge method is synthetic and cannot be called directly but it can be called using reflection. Of course they should not be called and doing so may result in error, e.g. a ClassCastException, when calling a bridge method with wrong parameter types.