Skip to content

Instantly share code, notes, and snippets.

@SmallEndian
Created November 7, 2018 13:54
Show Gist options
  • Select an option

  • Save SmallEndian/c4670bd8ee84d6f0801b34ac6896ba78 to your computer and use it in GitHub Desktop.

Select an option

Save SmallEndian/c4670bd8ee84d6f0801b34ac6896ba78 to your computer and use it in GitHub Desktop.
Some reflection on/about java
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);
}
}
}
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