定义了这样一些相似的类(动态加载),如何获取类的数组长度?或者指定下标的值?
public class FilterSet_1 { public static String[] eventType = null;
public static String[] domain = null;
public static String[] eventLevel = null;
public static String[] neType = null; static {
eventType = new String[]{
"BSUpload"
}; domain = new String[]{
"CONF",
"HWI",
"PM",
"RT"
}; eventLevel = new String[]{}; neType = new String[]{
"BS",
"Configuration Session",
"WAC",
"WACCL"
};
}比如,我想知道该类的neType[0]的值:BS。
public class FilterSet_1 { public static String[] eventType = null;
public static String[] domain = null;
public static String[] eventLevel = null;
public static String[] neType = null; static {
eventType = new String[]{
"BSUpload"
}; domain = new String[]{
"CONF",
"HWI",
"PM",
"RT"
}; eventLevel = new String[]{}; neType = new String[]{
"BS",
"Configuration Session",
"WAC",
"WACCL"
};
}比如,我想知道该类的neType[0]的值:BS。
以下代码给你参考,没有问题的
public class FilterSet_1 { public static String[] eventType = null;
public static String[] domain = null;
public static String[] eventLevel = null;
public static String[] neType = null;
public static void main(String args[])
{
domain = new String[]{"CONF","HWI", "PM","RT"}; eventLevel = new String[]{}; neType = new String[]{"BS", "Configuration Session","WAC","WACCL"};
//打印数组
System.out.println(neType.length);
//打印数组里指定索引的元素 ,索引从0开始
System.out.println(neType[0]);
}
static void f(){
eventType = new String[]{ "BSUpload"};
}
}
1,YidingHe(机枪兵))这些类有好多个,编译时产生,FilterSet_1, FilterSet_2,FilterSet_3, 只有运行时我才知道调用那个。public static void getEventLevel() {
try {
Class id = Class.forName("xxx.xxx.xxx.FilterSet_"+prjName); Field ob = null;
try{
ob = id.getField("eventLevel");
//这里只得到字段名称,不知道如何调用起值。
}
catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
}2,zhouquan1856() )这里是静态块,里面声明了很多静态数据(数组),不是方法。
---------------------------------------------------------这里是静态执行多个语句的写法,搂住没错。一般反编译里面这种东西比较多,哈哈。
楼主的问题不是很清楚什么意思,也许Class的下面这个方法你用得上getMethod(String name, Class[] parameterTypes)