How to delegate to an interface and provide only a no-arg public constructor?


#1

To avoid repeating myself, here is a link to my question on Stack Overflow: http://stackoverflow.com/q/37593738/986533


#2

You definitely won’t be able to extend ImmutableTable as its constructor is package-private. Can you elaborate on the intended usage a bit more? I think I have something that could work if you’re fine with your class just implementing Table rather than extending ImmutableTable but I want to be sure I understand the usage a little better.


#3

Thanks for clarification regarding ImmutableTable constructor. Silly mistake on my side. I thought there might be some other, non-obvious way around it.

Yes, Table is also fine by me, but I want to be able to call no-arg constructor of my class. Inside the constructor I would create my instance of the “base” Table to which all the method calls would delegate. But Kotlin’s class delegation feature forces me to actually pass such “base” Table as a constructor parameter. I cannot initialize it in constructor.

In this particular case I got lucky, because one person pointed out at Stack Overflow that I can just use ForwardingTable class which provides delegate method which allows me to circumvent Kotlin’s class delegation limitation.