程序如下:
import java.lang.annotation.Annotation;public @interface MyCommField
{ int length(); String type();
}////////////////////////////////
public class Goods
implements Serializable
{ @XinoCommField(length = 20,type="0030")
private String goods_id;
}
//////////////////////////////////////////
在另外一个类中。取得Goods的实例。
Class class1 = obj.getClass();
取所有的字段,其实就一个goods_id
Field afield[] = class1.getDeclaredFields();
但是下面这里有问题。
afield[0].isAnnotationPresent(MyCommField.class)总是为false。我想应该要为true才对。
请教高手帮忙解答。
import java.lang.annotation.Annotation;public @interface MyCommField
{ int length(); String type();
}////////////////////////////////
public class Goods
implements Serializable
{ @XinoCommField(length = 20,type="0030")
private String goods_id;
}
//////////////////////////////////////////
在另外一个类中。取得Goods的实例。
Class class1 = obj.getClass();
取所有的字段,其实就一个goods_id
Field afield[] = class1.getDeclaredFields();
但是下面这里有问题。
afield[0].isAnnotationPresent(MyCommField.class)总是为false。我想应该要为true才对。
请教高手帮忙解答。
解决方案 »
- 把连接ACCESS数据库换成SQLsever 代码应该怎样改?初学者 请指点!
- SOS:关于遍历目录问题
- 一个问题.
- 如果储存矢量图形?
- 求助,和JNI相关,Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x80C1548
- 说出你自己的理解:流(stream)到底是什么?你是怎么理解流(stream)的?
- jni问题!!!!
- Jbuider7的哪个目录底下java有文档?
- JAVA?有何IDE好用?有Solaris平台上JDK为何不能做到至Turbo C 2.0那样的?
- SCJP275要考GridBagLayout吗?怎么考啊?
- JAVA中接口和方法怎么看上去有些相同呀
- 坐标系
楼主【quzhenok】截止到2008-07-01 09:56:01的历史汇总数据(不包括此帖):
发帖数:1 发帖分:50
结贴数:1 结贴分:50
未结数:0 未结分:0
结贴率:100.00% 结分率:100.00%
敬礼!
这里改一下改为
@MyCommField(length = 20,type="0030")
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MyCommField {
int length();
String type();
}