| // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file | |
| // for details. All rights reserved. Use of this source code is governed by a | |
| // BSD-style license that can be found in the LICENSE file. | |
| package invokecustom; | |
| import java.lang.invoke.CallSite; | |
| import java.lang.invoke.ConstantCallSite; | |
| import java.lang.invoke.MethodHandle; | |
| import java.lang.invoke.MethodHandles; | |
| import java.lang.invoke.MethodType; | |
| public class InvokeCustom { | |
| private static String staticField1 = "StaticField1"; | |
| private static void targetMethodTest1() { | |
| System.out.println("Hello World!"); | |
| } | |
| private static void targetMethodTest2(MethodHandle mhInvokeStatic, MethodHandle mhGetStatic) | |
| throws Throwable { | |
| mhInvokeStatic.invokeExact(); | |
| System.out.println(mhGetStatic.invoke()); | |
| } | |
| private static void targetMethodTest3(MethodType mt) | |
| throws Throwable { | |
| System.out.println("MethodType: " + mt.toString()); | |
| } | |
| public static CallSite bsmLookupStatic(MethodHandles.Lookup caller, String name, MethodType type) | |
| throws NoSuchMethodException, IllegalAccessException { | |
| final MethodHandles.Lookup lookup = MethodHandles.lookup(); | |
| final MethodHandle targetMH = lookup.findStatic(lookup.lookupClass(), name, type); | |
| return new ConstantCallSite(targetMH.asType(type)); | |
| } | |
| } |