Created
June 23, 2012 14:58
-
-
Save phl0w/2978578 to your computer and use it in GitHub Desktop.
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; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| public class FieldsToArray { | |
| public int a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8, i = 0, | |
| j = 0, k = 0, l = 0; | |
| public static void main(String[] args) { | |
| FieldsToArray fta = new FieldsToArray(); | |
| List<Field> array = getList(); | |
| for (Field f : array) { | |
| try { | |
| System.out.println((Integer) f.getInt(fta)); | |
| } catch (IllegalArgumentException e) { | |
| e.printStackTrace(); | |
| } catch (IllegalAccessException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| public static List<Field> getList() { | |
| List<Field> toReturn = new ArrayList<Field>(); | |
| Field[] fields = FieldsToArray.class.getDeclaredFields(); | |
| for (Field f : fields) { | |
| if (f.getType().isPrimitive()) { | |
| toReturn.add(f); | |
| } | |
| } | |
| return toReturn; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment