Quantcast
Channel: Active questions tagged methodhandle - Stack Overflow
Viewing all articles
Browse latest Browse all 37

Methodhandle private method called using findVirtual

$
0
0

Java doc of MethodHandle says that private method should invoke via findSpecial.But in the following example I am able to invoke it via findVirtual.

Could somebody please explain what am I missing here?

import java.lang.invoke.MethodHandles;import java.lang.invoke.*;import java.lang.invoke.MethodType;public class PrivateClassMethodLookupTest{    public static void main(String[] args) throws Throwable{     new PrivateClassMethodLookupTest().m();     MethodHandle mh =   MethodHandles.lookup()                .findVirtual(PrivateClassMethodLookupTest.class, "m", MethodType.methodType(void.class));      mh.invoke(new PrivateClassMethodLookupTest());    }    private void m() { System.out.println("in m");}}

Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>