----- Original Message ----- From: "Zachary Mitchell" <[email protected]>
To: "POI Users List" <[email protected]>
Sent: Thursday, September 23, 2010 2:29 PM
Subject: HWPFDocument and _dataStream, via reflection.


//How Do I use reflection to get access to a private/protected field of a primitive array type,
//say byte [] ?

import java.lang.reflect.*;
import java.util.concurrent.*;
import java.util.*;


public class Reflection {


public static void main (String [] args)
{
class Fred {
private int array [] = {1,2,3,4,5,6,7};
Fred()
{}
private int getNumber()
{
return 7;}
}
class Thing extends Fred{
private Double item = 4.0;
Thing()
{}

private int getNumber()
{
return item.intValue();}
}

Fred fred = new Fred();

System.out.println();
Method [] methods = fred.getClass().getDeclaredMethods();
Field [] fields = fred.getClass().getDeclaredFields();
Field field =(Field) fields[0];

try {
field.setAccessible(true);
System.out.println(fred.getClass().getName());
System.out.println(field.getName());
System.out.println(field.getType());
System.out.println(field.get(fred));
}
catch (IllegalAccessException a)
{a.printStackTrace();}
System.out.println();

}
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to