ExtensibleObject relies on ClassToInstanceMap indirection through getExtensions() method. Since we have default methods (since Java 8), we can do better without the Guava tie-in:
interface ExtensibleObject { default <T extends E> @Nullable T extension(final Class<T> type) { // Iterate over availableExtension() and use isInstance() check } Collection<? extends E> supportedExtensions(); }
Given there typically are only one or two extensions, the search is equally-perfomant and users end up cleaner:
ExtensibleObject obj; var ext = obj.extension(FooExtension.class); // ... whatever
where previous they'd do:
ExtensibleObject obj; var ext = obj.getExtensions().getInstance(FooExtension.class); // ... whatever
This will make it slightly ugly for extensions which build on top of each other, but we have exactly 0 of those and, at the end on the day, they'd have to co-operate anyway, so a reasonable implementation would use the same object – and we cover that use case.