Created
November 7, 2018 13:54
-
-
Save SmallEndian/c4670bd8ee84d6f0801b34ac6896ba78 to your computer and use it in GitHub Desktop.
Some reflection on/about java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.File; | |
| import java.lang.reflect.Field; | |
| import java.net.URI; | |
| public class Container extends File { | |
| private String this_is_private; | |
| protected String this_is_protected; | |
| String this_is_package; | |
| public String this_is_public; | |
| public Integer valeur = 5; | |
| public Container(String s) { | |
| super(s); | |
| } | |
| public Container(String s, String s1) { | |
| super(s, s1); | |
| } | |
| public Container(File file, String s) { | |
| super(file, s); | |
| } | |
| public Container(URI uri) { | |
| super(uri); | |
| } | |
| Integer getValue(){ | |
| return valeur; | |
| } | |
| public void tell_me_about_you(){ | |
| Field[] fs = this.getClass().getDeclaredFields(); | |
| for(Field e :fs){ | |
| System.out.println(e); | |
| } | |
| fs = this.getClass().getSuperclass().getDeclaredFields(); | |
| for(Field e :fs){ | |
| System.out.println(e); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.lang.reflect.Field; | |
| public class Main { | |
| public static void main(String[] args){ | |
| Container f = new Container("/tmp/e"); | |
| Field[] s = f.getClass().getFields(); | |
| for(Field e : s){ | |
| System.out.println(e); | |
| } | |
| System.out.println("\n\n\t\t***\n\n"); | |
| f.tell_me_about_you(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment