Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. // package whatever; // don't place package name!
  2. import java.io.*;
  3. import java.lang.reflect.Method;
  4. import java.lang.reflect.InvocationTargetException;
  5.  
  6.  
  7. class MyCode {
  8.   public static void main (String[] args) {
  9.     System.out.println("Hello Java");
  10.    
  11.     Point3D p = new Point3D(1, 2, 3);
  12.     p.print();
  13. //     Class c = p.getClass();
  14.     Class c = Point3D.class;
  15. //     Class c = Class.forName("");
  16.     //Field f = c.getDeclaredField("x");
  17.     //f[1].setAccesable(true);
  18.     try {
  19.       Method m = c.getDeclaredMethod("print");
  20.       m.invoke(p);
  21.     } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {}
  22.   }
  23.  
  24. //   @Annotation
  25.   public static class Point {
  26.     int x;
  27.     int y;
  28.    
  29.     public Point(int x, int y) {
  30.       this.x = x;
  31.       this.y = y;
  32.     }
  33.    
  34.     public void print() {
  35.             System.out.println(x + " " + y);
  36.     }
  37.   }
  38.  
  39. //   @Annotatoin
  40.   public static class Point3D extends Point {
  41.     int z;
  42.    
  43.     public Point3D(int x, int y, int z) {
  44.       super(x, y);
  45.       this.z = z;
  46.     }
  47.    
  48.     @Override
  49. //     @Annotation(str2 = "Test1")
  50. //     @Annotation1(@Annotation)
  51. //     @Annotation(str2 = "Check")
  52.     public void print() {
  53.       System.out.println(x + " " + y + " " + z);
  54.     }
  55.   }
  56.  
  57. //   @Retention(RetentionPolicy.RUNTIME)
  58. // //   @Target(ElementType.METHOD)
  59. //   @Inherited
  60. //   public @interface Annotation {
  61. //  String str1() default
  62. //     String str2() default "";
  63. //   }
  64.  
  65. //   public @interface Annotation1 {
  66. //     Annotaion value();
  67. //   }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement