Java Generics: Multiple Type Parameters
A generic class can have multiple type parameters. For example, the generic GenericEntryImpl, which implements the generic IGenericEntry interface:
IGenericEntry.java:
GenericEntryImpl.java:
GenericEntryTest.java:
Note:
Output:
Entry 1 -> Key:Nithi, Value:30
Entry 2 -> Key:Hello, Value:World
IGenericEntry.java:
GenericEntryImpl.java:
GenericEntryTest.java:
Note:
- Due to autoboxing it is valid to pass a String and an int to the class.
- Java Compiler will take care of automatic conversion from an int to Integer.
Output:
Entry 1 -> Key:Nithi, Value:30
Entry 2 -> Key:Hello, Value:World
0 comments:
Post a Comment