Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // package whatever; // don't place package name!
- import java.io.*;
- import java.lang.reflect.Method;
- import java.lang.reflect.InvocationTargetException;
- class MyCode {
- public static void main (String[] args) {
- System.out.println("Hello Java");
- Point3D p = new Point3D(1, 2, 3);
- p.print();
- // Class c = p.getClass();
- Class c = Point3D.class;
- // Class c = Class.forName("");
- //Field f = c.getDeclaredField("x");
- //f[1].setAccesable(true);
- try {
- Method m = c.getDeclaredMethod("print");
- m.invoke(p);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {}
- }
- // @Annotation
- public static class Point {
- int x;
- int y;
- public Point(int x, int y) {
- this.x = x;
- this.y = y;
- }
- public void print() {
- System.out.println(x + " " + y);
- }
- }
- // @Annotatoin
- public static class Point3D extends Point {
- int z;
- public Point3D(int x, int y, int z) {
- super(x, y);
- this.z = z;
- }
- @Override
- // @Annotation(str2 = "Test1")
- // @Annotation1(@Annotation)
- // @Annotation(str2 = "Check")
- public void print() {
- System.out.println(x + " " + y + " " + z);
- }
- }
- // @Retention(RetentionPolicy.RUNTIME)
- // // @Target(ElementType.METHOD)
- // @Inherited
- // public @interface Annotation {
- // String str1() default
- // String str2() default "";
- // }
- // public @interface Annotation1 {
- // Annotaion value();
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement