SHARE
TWEET

NonVirtualTest

a guest Jan 4th, 2017 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package pack;
  2.  
  3. import natan12_.util.natives.Nonvirtual;
  4.  
  5. public class NonVirtualTest
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         a a = new b();
  10.         System.out.format("Direct invocation: '%s'%n", a.s()); //prints "Direct invocation: 'inside b'"
  11.         System.out.format("Nonvirtual invocation: '%s'%n",
  12.             Nonvirtual.callNonvirtualObjectMethod(
  13.                 a.class, /*class declaring the method*/
  14.                 a, /* instance */
  15.                 "s", /*method name*/
  16.                 "()Ljava/lang/String;" /*signature (use Nonvirtual.getSignature(Class, Class[]) or Nonvirtual.getSignature(Method)*/
  17.             )
  18.         ); //prints "Nonvirtual invocation: 'inside a'"
  19.     }
  20.    
  21.     static class a
  22.     {
  23.         public String s()
  24.         {
  25.             return "inside a";
  26.         }
  27.     }
  28.  
  29.     static class b extends a
  30.     {
  31.         @Override
  32.         public String s()
  33.         {
  34.             return "inside b";
  35.         }
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top