Bridge Method

Java-Bridge Method

Bridge Method Sometimes, the compiler will need to add a bridge method to a class to handle situations in which the type erasure of an overriding method in a subclass does not produce the same erasure as the method in the superclass. In this case, a method is generated that uses the type erasure of … Read more…

Overriding Methods

Java-Overriding Methods

Overriding Methods A method in a generic class can be overridden just like any other method. For example, consider the following program in which the method getT( ) is overridden. As the output confirms, the overridden version of getT( ) is called for object of type GenTwo, but you can call the superclass version via GenOne object. … Read more…

Generic Superclass

Java-Generic Superclass

Generic Superclass Generic classes can be part of a class hierarchy in just the same way as a non-generic class. Thus, a generic class can act as a superclass or be a subclass. The key difference between generic and non-generic hierarchies is that in a generic hierarchy, any type arguments needed by a generic superclass … Read more…

Raw Type Troubles

Java-Raw Type Troubles

Raw Type Troubles A raw type is not type safe. Consider the following statement : The value of t1 inside rgen is obtained, and this value is cast to Integer. The trouble is that rgen contains a String, not an Integer. However, this cannot be detected at compile time because the type of rgen is … Read more…

Raw Types

Java-Raw Types

Raw Types Although the compiler treats different parameterizations of a generic type as different types (with different APIs) at compile time, but only one real type exists at runtime. For example, the class of Gen<Integer> and Gen<String> share the plain Java class Gen : Gen is called the raw type of the generic class. Every generic … Read more…