Skip to content
Advertisement

Passing function as argument to a Function, and using it on Generic object

I would like to do something like below.

JavaScript

A and B class will be my generic type as <T>. Example for a getter function for class A and B.

JavaScript

I want to pass a getterFunction as argument to my sliceGenericData() and I would like to use it on type <T> (Class A or B). Since those classes have different name of getter functions as getterFunction2, getterFunction1. How can I do it?

Advertisement

Answer

You can pass a function taking the type as param and producing a Long like this:

JavaScript

Invoke the method by providing the appropriate method for the type:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement