There are two issues here:
- allowing the compiler to generate efficient code,
- reusing code when extending behavior.
Regarding (1), don’t worry about it too much. The first version of getv1
will compile for concrete types, and will be efficient. It should not be necessary to document return types, the compiler will figure it out (in general, methods should just be type-stable.
Regarding (2), see the discussion here.