Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 72 inside the jvm Represents the type signature of a method Consists of the return type followed by the argument types Does not include the receiver type or name of the method Is designed to remove the Class problem from core reflection In addition instances of it are immutable With this API signatures of methods are represented as instances of MethodType and there is no need to create a new type to model each possible signature New instances are created from a simple factory method toString MethodType mtToString MethodType methodType String class A setter method MethodType mtSetter MethodType methodType void class Object class compare from Comparator String MethodType mtStringComparator MethodType methodType int class String class String class Once you have created a signature object it can be used along with a method name to look up a method handle as in the following example to get a method handle on toString public MethodHandle getToStringHandle MethodHandle mh null MethodType mt MethodType methodType String class MethodHandles Lookup lk MethodHandles lookup try mh lk findVirtual getClass toString mt
You must have JavaScript enabled to view digital editions.