September 2019
Intermediate to advanced
816 pages
18h 47m
English
For example, let's get the generic return types for the slice() and asMap() methods. This can be accomplished via the Method.getGenericReturnType() method as follows:
Class<Melon> clazz = Melon.class;Method sliceMethod = clazz.getDeclaredMethod("slice");Method asMapMethod = clazz.getDeclaredMethod("asMap", List.class);Type sliceReturnType = sliceMethod.getGenericReturnType();Type asMapReturnType = asMapMethod.getGenericReturnType();
Now, calling printGenerics(sliceReturnType) will output the following:
Class of type argument: class modern.challenge.SliceSimple name of type argument: Slice
And, calling printGenerics(asMapReturnType) will output the following:
Class of type argument: class java.lang.StringSimple name of ...